// 创建方式
UILabel *lb = [[UILabel alloc]init];
// 放在view上显示
[self.view addSubview:lb];
// 设置frame
lb.frame = CGRectMake(20, 200, 300, 60);
// 设置背景色
// lb.backgroundColor = [UIColor redColor];
// 设置文字
lb.text = @"夕阳下的奔跑,那是我逝去的青春啊";
// 设置文字颜色
lb.textColor = [UIColor grayColor];
// 设置文字类型 和大小
lb.font = [UIFont systemFontOfSize:17.0];
// 获取字体库
// NSLog(@"%@",[UIFont familyNames]);
// 设置对齐方式
lb.textAlignment = NSTextAlignmentCenter;
// 设置 attributedText
// lb.attributedText = [[NSAttributedString alloc]initWithString:@"夕阳下的奔跑,那是我逝去的青春啊" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17.0],NSForegroundColorAttributeName:[UIColor redColor]}];
// 切段模式 根据单词 还是字母换行之类的 中文不存在这个
// lb.lineBreakMode = NSLineBreakByWordWrapping ... NSLineBreakByCharWrapping.. NSLineBreakByClipping ....
//设置显示最大行数 默认为1;0代表无限制
lb.numberOfLines = 0;
// [lb sizeToFit]; 改变size适应文字
// lb.adjustsFontSizeToFitWidth = YES; 改变字体大小适应宽度
// 设置阴影颜色 设置后显示
lb.shadowColor = [UIColor greenColor];
// 设置阴影的偏移量 超出lb frame部分不显示
lb.shadowOffset = CGSizeMake(20, 20);
// 涉及到计算文字的size
NSString *str = @"夕阳下的奔跑,那是我逝去的青春啊";
CGSize size = [str boundingRectWithSize:CGSizeMake(100, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17.0]} context:nil].size;
NSLog(@"%.f %.f",size.width,size.height); 结果 85 81