IBInspectable storyboard 中直接修改边框颜色和边框宽度
IB_DESIGNABLE storyboard 中直接显示出圆角效果
效果图
storyboard 中直接修改边框颜色和边框宽度
<img src=http://www.boitx.org/ios/IBInspectable/1.gif width=600>
storyboard 中直接显示出圆角效果
<img src=http://www.boitx.org/ios/IBInspectable/2.gif width=900>
IBInspectable
用 IBInspectable 声明变量,变量会直接显示到 storyboard 中 属性检查器里面,会像修改 view 颜色一样方便的进行修改。
@property (nonatomic,strong) IBInspectable UIColor *borderC;
@property (nonatomic,assign) IBInspectable CGFloat borderWidth;
IB_DESIGNABLE
声明类,对类进行自定义,自定义效果会直接显示到 storyboard 中。
IB_DESIGNABLE
@interface BorderView : UIView
核心代码
BorderView.h
#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interface BorderView : UIView
@property (nonatomic,strong) IBInspectable UIColor *borderC;
@property (nonatomic,assign) IBInspectable CGFloat borderWidth;
@end
BorderView.m
#import "BorderView.h"
@implementation BorderView
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.layer.masksToBounds = YES;
self.layer.cornerRadius = 50;
}
return self;
}
- (void)setBorderC:(UIColor *)borderC
{
_borderC = borderC;
self.layer.borderColor = borderC.CGColor;
}
- (void)setBorderWidth:(CGFloat)borderWidth
{
_borderWidth = borderWidth;
self.layer.borderWidth = borderWidth;
}
@end
网友评论