view层控件比较优雅写法

2018-12-19  本文已影响0人  lifeLL
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;
}

上一篇 下一篇

猜你喜欢

热点阅读