屏幕快照 2019-03-20 23.27.10.png直接在IB界面设置圆角边框颜色
屏幕快照 2019-03-20 23.29.59.png运行结果
可以看到直接在xib中属性设置的圆角边框成功啦!
贴一下代码.h
IB_DESIGNABLE // 动态刷新
@interface UIView (YHXibExtension)
@property (assign, nonatomic) IBInspectable CGFloat cornerRadius;
@property (assign, nonatomic) IBInspectable CGFloat borderWidth;
@property (strong, nonatomic) IBInspectable UIColor *borderColor;
@end
贴一下代码.m
@implementation UIView (YHXibExtension)
@dynamic cornerRadius;
@dynamic borderWidth;
@dynamic borderColor;
- (void)setCornerRadius:(CGFloat)cornerRadius {
self.layer.cornerRadius = cornerRadius;
self.layer.masksToBounds = (cornerRadius>0);
}
- (CGFloat)cornerRadius {
return self.layer.cornerRadius;
}
- (void)setBorderWidth:(CGFloat)borderWidth {
self.layer.borderWidth = borderWidth;
}
- (CGFloat)borderWidth {
return self.layer.borderWidth;
}
- (void)setBorderColor:(UIColor *)borderColor {
self.layer.borderColor = borderColor.CGColor;
}
- (UIColor *)borderColor {
return [UIColor colorWithCGColor:self.layer.borderColor];
}
网友评论