青干欧阳的博客

码农的历程

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

#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
阅读更多
版权声明:青干欧阳技术博客 https://blog.csdn.net/qq_40598646/article/details/80689197
个人分类: runtime
想对作者说点什么? 我来说一句

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

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭