在SB中控件可以在SB中直接利用kvc 设置一些属性值,不如layerwidth等 但是不能更改和颜色有关的属性因为layerbordercolor是CGColor.通过为CALayer增加属性可以实现在SB中也能用KVC设置layerbordercolor;新建CALayer的分类
@interface CALayer (WjlCALayer)
/**
* 在SB中设置keypath就可以改变boredercolor的颜色
*/
@property(nonatomic, strong) UIColor *borderColorFromUIColor;
//- (void)setBorderColorFromUIColor:(UIColor *)color; @implementation CALayer (WjlCALayer)
- (UIColor *)borderColorFromUIColor { return objc_getAssociatedObject(self, @selector(borderColorFromUIColor));
}
-(void)setBorderColorFromUIColor:(UIColor *)color
{
objc_setAssociatedObject(self, @selector(borderColorFromUIColor), color, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self setBorderColorFromUI:color];
}
- (void)setBorderColorFromUI:(UIColor *)color
{
self.borderColor = color.CGColor; }
@end