第1年4月22日 IBInspectable巧妙用法 cornerRadius

1.

@implementation UIView (Design)

@dynamic cornerRadius,borderColor,borderWidth;

#define CornerRadius_Key @"CornerRadius_Key"
#define BorderWidth_Key @"BorderWidth_Key"
#define BorderColor_Key @"BorderColor_Key"

#pragma mark - UIView + corner and broder
- (CGFloat)cornerRadius{
    NSNumber *key = (NSNumber *)objc_getAssociatedObject(self, CornerRadius_Key);
    return key.doubleValue;
}

-(void)setCornerRadius:(CGFloat)cornerRadius
{
    objc_setAssociatedObject(self, CornerRadius_Key, [NSNumber numberWithDouble:cornerRadius], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    self.layer.cornerRadius = cornerRadius;
    self.layer.masksToBounds = YES;
}

https://www.jianshu.com/p/82c617ae3c97

原文地址:https://www.cnblogs.com/javastart/p/14688916.html