ios object-c 自定义可视编辑圆角与边框
1、常用控件:
- UILabel、UIButton、UITextView、UIImageView、UITextField、UIView
复制代码 2、示例代码:
BaseLabel.h
- #import <UIKit/UIKit.h>
- NS_ASSUME_NONNULL_BEGIN
- //IB_DESIGNABLE
- @interface BaseLabel : UILabel
- @property (nonatomic, assign) IBInspectable CGFloat cornerRadius; /**< 圆角半径 */
- @property (nonatomic, strong) IBInspectable UIColor* borderColor; /**< 边框颜色 */
- @property (nonatomic, assign) IBInspectable CGFloat borderWidth; /**< 边框宽度 */
- @end
复制代码 BaseLabel.m
- #import "BaseLabel.h"
- @implementation BaseLabel
- //
- - (void)setCornerRadius:(CGFloat)cornerRadius
- {
- _cornerRadius = cornerRadius;
- self.layer.cornerRadius = cornerRadius;
- self.layer.masksToBounds = cornerRadius > 0 ? YES : NO;
- self.layer.shouldRasterize = YES;
- self.layer.rasterizationScale = [UIScreen mainScreen].scale;
- }
- - (void)setBorderColor:(UIColor *)borderColor
- {
- _borderColor = [borderColor copy];
- self.layer.borderColor = borderColor.CGColor;
- }
- - (void)setBorderWidth:(CGFloat)borderWidth
- {
- _borderWidth = borderWidth;
- self.layer.borderWidth = borderWidth;
- }
- @end
复制代码 3、利用
因IB_DESIGNABLE 被注释因此设置完成后,只有在运行时控件才表现圆角,想设置时表现的去掉注释即可
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |