1.创建UIlabel
1 | UILabel *label1 = [[UILabelalloc] initWithFrame:CGRectMake(20, 40, 280, 80)]; |
2.设置背景色
1 | label1.backgroundColor = [UIColor grayColor]; |
3.设置tag
1 | label1.tag = 91; |
4.设置标签文本
1 | label1.text = @"Hello world!"; |
5.设置标签文本字体和字体大小
1 | label1.font = [UIFont fontWithName:@"Arial" size:30]; |
6.设置文本对其方式
1 | label1.textAlignment = UITextAlignmentCenter; |
文本对齐方式有以下三种
1 2 3 4 5 6 7 8 | typedef enum { UITextAlignmentLeft = 0,左对齐 UITextAlignmentCenter,居中对齐 UITextAlignmentRight, 右对齐 } UITextAlignment; |
[……]