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];
        // 設(shè)置label內(nèi)容
        _name.text = @"標(biāo)題";
        // 設(shè)置字體顏色
        _name.textColor = [UIColor redColor];
        // 自定義背景顏色(通過RGB值改顏色)
        _name.backgroundColor = [UIColor colorWithRed:0 green:205 blue:205 alpha:0.5];
        // 設(shè)置系統(tǒng)字體
        _name.font = [UIFont systemFontOfSize:20];
        //_name.font = [UIFont fontWithName:<#(NSString *)#> size:<#(CGFloat)#>];
        // 對其方式 (居中對其,左對齊,右對齊)
        _name.textAlignment = NSTextAlignmentCenter;
        // 設(shè)置行數(shù)
        _name.numberOfLines = 0;
        // 斷行模式
        _name.lineBreakMode = NSLineBreakByTruncatingMiddle;
        // 設(shè)置陰影顏色
        _name.shadowColor = [UIColor purpleColor];
        // 設(shè)置引用偏移量
        _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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容