美文网首页
view层控件比较优雅写法

view层控件比较优雅写法

作者: lifeLL | 来源:发表于2018-12-19 16:19 被阅读0次
From >>> https://github.com/ChangBoHua/CBUIKit
感觉这种写法可以节省很多代码,比较优雅,之前有用过vc分类来写,在view上就不能用,有点局限,还是用object来的方便
//调用
- (UILabel *)currentLabel{

    if (!_currentLabel) {
        _currentLabel = [CBUIKit createLabelWithTextColor:[UIColor orangeColor]
                                                 fontSize:15];
    }
    return _currentLabel;
}
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface CBUIKit : NSObject

+ (UILabel *)createLabelWithTextColor:(UIColor *)textColor
                        fontSize:(CGFloat)fontSize;
@implementation CBUIKit
+ (UILabel *)createLabelWithTextColor:(UIColor *)textColor
                             fontSize:(CGFloat)fontSize{
   UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.backgroundColor = backgroundColor;
    label.textColor = textColor;
    label.textAlignment = textAlignment;
    label.numberOfLines = numberOfLines;
    label.text = text;
    label.font = [UIFont systemFontOfSize:fontSize];
    return label;
}

相关文章

网友评论

      本文标题:view层控件比较优雅写法

      本文链接:https://www.haomeiwen.com/subject/uogsoxtx.html