#define kWidth (self.view.bounds.size.width) //宏:宽度
#define kHeight (self.view.bounds.size.height)//界面高度
#import "PickViewCell.h" //导入拾取器视图自定义文件的头
//全局变量
- (instancetype)init {
self = [super init];
if (self) {
self.backgroundColor=[UIColor blackColor];//设置背景色
[self _createTitleLable];//创建组件
}
return self;
}
#pragma mark - 创建组件
- (void)_createTitleLable {
//创建标题标签
_labelTitle = [[UILabel alloc] init];
_labelTitle.textColor = [UIColor whiteColor];
_labelTitle.textAlignment = NSTextAlignmentCenter;
_labelTitle.font = [UIFont boldSystemFontOfSize:17];
[self addSubview:_labelTitle];
}
- (void)setTitle:(NSString *)title {
_title = title;//赋值
[self setNeedsLayout];
}
//重写的方法
- (void)layoutSubviews {
[super layoutSubviews];
[self _layout];//属性赋值
}
//重新对标题赋值
- (void)_layout {
CGRect rectTemp = self.bounds;
_labelTitle.frame = rectTemp;
_labelTitle.text = _title;
}
联系客服