UILable 即文字顯示便簽
初始化方法
UILabel *label = [[UILable alloc]init];
UILabel *label = [UIlable New];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 200)];
常用屬性
@property(nullable, nonatomic,copy) NSString *text; // default is nil 默認(rèn)為nil是趴,text 即標(biāo)簽顯示的內(nèi)容,例如 label.text = @"天王蓋地虎";
@property(null_resettable, nonatomic,strong) UIFont *font; // -default is nil (system font 17 plain) 默認(rèn)nil 澄惊,不設(shè)置會(huì)跟隨你的高度唆途,font 即顯示內(nèi)容字體的大小 例如 label.font = [ UIFont systemFontOfSize:20 ]; 則是設(shè)置字體為系統(tǒng)字體20號(hào)字
@property(null_resettable, nonatomic,strong) UIColor *textColor; //標(biāo)簽文字顏色肛搬,例如 label.textColor =[UIColor whiteColor]; @property(nonatomic) NSTextAlignment textAlignment; //標(biāo)簽的對(duì)齊方式毕贼,默認(rèn)左對(duì)齊,可選左,中,右
label.textAlignment = NSTextAlignmentCenter; //居中
label.textAlignment = NSTextAlignmentLeft; //左對(duì)齊
label.textAlignment = NSTextAlignmentRight;//右對(duì)齊
@property(nonatomic) NSInteger numberOfLines;//標(biāo)簽文字的行數(shù)陶贼,默認(rèn)為一行,設(shè)置為0 則不限制 例如 lab.numberOfLines = 0; label.numberOfLines = 2;
創(chuàng)建一個(gè) Hello World 標(biāo)簽并添加到視圖
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(50,100, 300, 20)];
label.text= @"Hello World";
[self.view addSubview:label];
設(shè)置文字居中痹屹,字體顏色為白色志衍,字體大小為10號(hào)
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont systemFontOfSize:10];
label.textColor = [UIColor whiteColor];