iOS 给xib, storyboard添加可视设置属性

2019-04-03  本文已影响0人  飞不越疯人院

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

最终效果: xib或者storyboard中新增了三个属性:

image
上一篇 下一篇

猜你喜欢

热点阅读