#import "UILabel+zjLabel.h"
@implementation UILabel (zjLabel)
+ (UILabel *)zj_createLabel:(void (^)(UILabel * _Nonnull))block{
UILabel *label = [UILabel new];
block(label);
return label;
}
- (UILabel *(^)(NSString *))zj_text{
return ^(NSString *str){
self.text = str;
return self;
};
}
- (UILabel *(^)(UIFont *))zj_font{
return ^(UIFont *font){
self.font = font;
return self;
};
}
- (UILabel *(^)(UIColor *))zj_textColor{
return ^(UIColor *color){
self.textColor = color;
return self;
};
}
- (UILabel *(^)(NSTextAlignment))zj_textAlignment{
return ^(NSTextAlignment aligment){
self.textAlignment = aligment;
return self;
};
}
在需要的地方调用方式如下:
UILabel *label = [UILabel zj_createLabel:^(UILabel * _Nonnull label) {
label.zj_text(@"haha").zj_font([UIFont systemFontOfSize:24]).zj_textColor(UIColor.redColor);
}];
[superview addSubview:label];
网友评论