IBInspectable :添加属性,示例如下:文件和代码
#import <UIKit/UIKit.h>
@interface UIView (ViewAddtion)
///倒角
@property (nonatomic, assign) IBInspectable double xCornerRadius;
///边框颜色
@property (nonatomic, strong) IBInspectable UIColor *borderColor;
///边框宽度
@property (nonatomic, assign) IBInspectable double borderWidth;
@end
#import "UIView+ViewAddtion.h"
@implementation UIView (ViewAddtion)
- (void)setXCornerRadius:(double)xCornerRadius {
self.layer.cornerRadius = xCornerRadius;
self.layer.masksToBounds = YES;
}
- (double)xCornerRadius {
return self.layer.cornerRadius;
}
- (void)setBorderColor:(UIColor *)borderColor {
self.layer.borderColor = borderColor.CGColor;
}
- (UIColor *)borderColor {
return [UIColor colorWithCGColor:self.layer.borderColor];
}
- (void)setBorderWidth:(double)borderWidth {
self.layer.borderWidth = borderWidth;
}
- (double)borderWidth {
return self.layer.borderWidth;
}
@end