1、创建
UILabel *label = [[UILabel alloc] init];
2、设置大小
label.frame = CGRectMake(0, 100, 100, 20);
3、设置背景颜色
label.backgroundColor = [UIColor yellowColor];
4、设置文字
label.text = @"设置UILabel的文字";
5、设置文字颜色
label.textColor = [UIColor redColor];
6、设置文字字体及大小
label.font = [UIFont systemFontOfSize:20]; // 系统字体 20号
[label.font = [UIFont fontWithName:Noteworthy size:20]; // 指定字体 20号
label.font = [UIFont boldSystemFontOfSize:20]; // 系统加粗 20号
7、设置文字阴影和及阴影颜色
label.shadowOffset = CGSizeMake(5, 5);
label.shadowColor = [UIColor blackColor];
8、设置倒角及倒角边缘宽度、颜色
label.layer.cornerRadius = 10;
label.layer.borderWidth = 1.5;
label.layer.borderColor = [UIColor redColor] CGColor];
9、设置文字位置:左、中、右
label.textAlignment = NSTextAlignmentLeft;
label.textAlignment = NSTextAlignmentCenter;
label.textAlignment = NSTextAlignmentRight;
10、设置指定显示行数(默认是1行)
label.numberOfLines = 2;
11、设置动态显示行数
第一步:
label.numberOfLines = 0;
第二步:
CGSize realSize = [text sizeWithFont:label.font constrainedToSize:CGSizeMake(300, 1000)];
第三步:
label.frame = CGRectMake(0, 30, realSize.width, realSize.height);
12、获取系统所有字体
NSArray *fontsArr = [UIFont familyNames];
NSLog(@"fontsArr = %@", fonts);