天天看點

IOS UILabel的常用屬性

// 執行個體化UILabel并指定其邊框

UILabel*label = [[UILabel alloc]initWithFrame:CGRectMake(0.0, 210.0, 320.0, 40.0)];

// 設定label顯示的文本

[label setText:@"HelloWorld"];

// 設定字型和字型大小

[label setFont:[UIFont fontWithName:@"Helvetica-Bold" size:40]];

// 設定背景色

[label setBackgroundColor:[UIColor greenColor]];

// 設定文本的顔色

[label setTextColor:[UIColor whiteColor]];

// 設定文本的陰影色彩和透明度

[label setShadowColor:[UIColor colorWithWhite:0.1f alpha:0.8f]];

// 設定陰影的偏移量

[label setShadowOffset:CGSizeMake(2.0f, 2.0f)];

// 設定文本在label中的對齊方式

[label setTextAlignment:NSTextAlignmentCenter];

// 換行技巧:如下換行可實作多行顯示,但要求label有足夠的寬度。

// 指定換行模式

[label setLineBreakMode:NSLineBreakByWordWrapping];

// 指定label的行數,為0時沒有最大行數限制

[label setNumberOfLines:2];

// 設定label的旋轉角度

[label setTransform:CGAffineTransformMakeRotation(M_PI_4)];