UIKit之UILabel

#import "TestController.h"

@interface TestController ()
@property (strong, nonatomic)UILabel *name;
@end

@implementation TestController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

#pragma mark - lazyload
- (UILabel *)name{
    if (!_name) {
        _name = [UILabel new];
        _name.backgroundColor = [UIColor grayColor];
        [self.view addSubview: _name];
        // 设置label内容
        _name.text = @"标题";
        // 设置字体颜色
        _name.textColor = [UIColor redColor];
        // 自定义背景颜色(通过RGB值改颜色)
        _name.backgroundColor = [UIColor colorWithRed:0 green:205 blue:205 alpha:0.5];
        // 设置系统字体
        _name.font = [UIFont systemFontOfSize:20];
        //_name.font = [UIFont fontWithName:<#(NSString *)#> size:<#(CGFloat)#>];
        // 对其方式 (居中对其,左对齐,右对齐)
        _name.textAlignment = NSTextAlignmentCenter;
        // 设置行数
        _name.numberOfLines = 0;
        // 断行模式
        _name.lineBreakMode = NSLineBreakByTruncatingMiddle;
        // 设置阴影颜色
        _name.shadowColor = [UIColor purpleColor];
        // 设置引用偏移量
        _name.shadowOffset = CGSizeMake(10, 10);
        
        // masory布局
        [_name mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self.view);
            make.height.mas_equalTo(@50);
        }];
    }
    return _name;
}

@end

你可能感兴趣的:(UIKit之UILabel)