XIB 使用 runtime添加button 的cornerRadius,borderWidth,borderColor属性

版权声明:青干欧阳技术博客 https://blog.csdn.net/qq_40598646/article/details/80689197
#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interfaceUIView (CornerRadius)
@property(nonatomicassign)IBInspectableCGFloatcornerRadius;
@property(nonatomicassign)IBInspectableCGFloatborderWidth;
@property(nonatomicstrong)IBInspectableUIColor*borderColor;
@end


#import "Viewall.h"
#import <objc/runtime.h>
@implementationUIView (CornerRadius)
- (CGFloat)cornerRadius
{
    return[objc_getAssociatedObject(self@selector(cornerRadius)) floatValue];
}
- (void)setCornerRadius:(CGFloat)cornerRadius
{
    self.layer.cornerRadius= cornerRadius;
    self.layer.masksToBoundsYES;
}
- (CGFloat)borderWidth
{
    return[objc_getAssociatedObject(self@selector(borderWidth)) floatValue];
}
- (void)setBorderWidth:(CGFloat)borderWidth
{
    self.layer.borderWidth= borderWidth;
    self.layer.masksToBoundsYES;
}
- (UIColor*)borderColor
{
    returnobjc_getAssociatedObject(self@selector(borderColor));
}
- (void)setBorderColor:(UIColor*)borderColor
{
    self.layer.borderColor= borderColor.CGColor;
}
@end
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页