1.直接在Xcode的API Reference里面搜
IBInspectable 上面是Apple的英文教程。特别赞
2.带你走一遍
创建一个类比如
IBInspectableView
在类的开始@interface 上面写上
IB_DESIGNABLE 这样的一个宏定义
然后加入两个属性,分别控制边的粗细和颜色
@property(nonatomic)IBInspectableNSInteger lineWidth;
@property(nonatomic)IBInspectableUIColor*fillColor;
重写DrawRect方法
- (void)drawRect:(CGRect)rect {
CGContextRef context=UIGraphicsGetCurrentContext();
CGRect myFrame=self.bounds;
CGContextSetLineWidth(context,_lineWidth);
CGRectInset(myFrame,5, 5);
[_fillColorset];
//向当前绘图环境所创建的内存中的图片上绘制一个矩形边框
UIRectFrame(myFrame);
}
3.
在xib中创建一个对应的View与当前View相关联
运行会发现
多了2条属性。从此就告别了在Ru 手动创建的苦逼日子~