iOS IBInspectable和IB_DESIGNABLE

释放双眼,带上耳机,听听看~!

1.使用IBInspectable可以在xib/storyboard中方便的为类设置属性并看到效果.
在.h文件中声明属性,在属性中加关键字IBInspectable

#import <UIKit/UIKit.h>
@interface XYButton : UIButton
@property (nonatomic, assign) IBInspectable CGFloat connerRadius;
@property (nonatomic, assign) IBInspectable CGFloat borderWidth;
@property (nonatomic, assign) IBInspectable UIColor *borderColor;
@end

然后在.m文件中添加IB_DESIGNABLE关键字。如果不加IB_DESIGNABLE,不能再xib中实时看到效果

#import "XYButton.h"
IB_DESIGNABLE
@implementation XYButton
- (void)setConnerRadius:(CGFloat)connerRadius {
_connerRadius = connerRadius;
self.layer.cornerRadius = _connerRadius;
self.layer.masksToBounds = YES;
}
- (void)setBorderWidth:(CGFloat)borderWidth {
_borderWidth = borderWidth;
self.layer.borderWidth = _borderWidth;
}
- (void)setBorderColor:(UIColor *)borderColor {
_borderColor = borderColor;
self.layer.borderColor = _borderColor.CGColor;
}
@end

效果:
这里写图片描述

人已赞赏
iOS文章

iOS关于The dependency `AFNetworking` is not used in any concrete target的问题

2020-2-22 11:23:07

iOS文章

iOS UILabel长按复制

2020-2-22 12:24:04

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索