第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

posted @ 2021-04-22 11:54  lianhuaren  阅读(54)  评论(0编辑  收藏  举报