label.text = @"欢迎收看灌篮高手,我是安溪教练";
**//设置文字颜色
label.textColor = [UIColor grayColor];
**//默认17号字体
label.font = [UIFont systemFontOfSize:34];
**//对齐方式
label.textAlignment = NSTextAlignmentCenter;
**//设置阴影
label.shadowColor = [UIColor redColor];
//设置阴影映射大小(坐标),默认CGSizeMake(0, -1)
label.shadowOffset = CGSizeMake(-2, -2);
***//断句,展示缩略
label.lineBreakMode = NSLineBreakByTruncatingTail;
**//行数0为自动匹配行数
label.numberOfLines = 1;
***//字体是否适应宽度(Size无效)(将宽度充满)
label.adjustsFontSizeToFitWidth = YES;
//最小字体比例(缩放)
label.minimumScaleFactor = 0.9;
**//label背景色
label.backgroundColor = [UIColor yellowColor];
//设置高亮颜色
label.highlightedTextColor = [UIColor greenColor];
//开启高亮状态
label.highlighted = YES;
//是否隐藏高亮状态
label.hidden = NO;
2、UIFont
//打印苹果自带字体
for (NSString* str in [UIFont familyNames]) {
NSLog(@"%@",str);
NSArray* arr = [UIFont fontNamesForFamilyName:str];
for (NSString* str1 in arr) {
NSLog(@"%@",str1);
}
}
//斜体
[UIFont italicSystemFontOfSize:50];
//字体加粗
[UIFont boldSystemFontOfSize:50];
//设置系统字体
[UIFont systemFontOfSize:10];
//设置自定义字体
[UIFont fontWithName:@"Heiti TC" size:25];
//修改字体
[[UIFont systemFontOfSize:10] fontWithSize:50];
富文本
3、NSAttributedString
NSAttributedString * attribute = [[NSAttributedString alloc] initWithString:string attributes:dictA];
label.attributedText = attribute;
- addAttributes//分段操作字符串
(字典类型)
NSFontAttributeName:[UIFont systemFontOfSize:20],//字体大小
NSForegroundColorAttributeName:[UIColor greenColor]//字体颜色
NSBackgroundColorAttributeName:[UIColor grayColor]//字体背景颜色
NSParagraphStyleAttributeName:paragraph//段落属性
NSObliquenessAttributeName:@0.5 //斜体
NSStrokeColorAttributeName:[UIColor whiteColor],//边线颜色
NSStrokeWidthAttributeName:@2,//描边
NSKernAttributeName:@20,//字间距
NSStrikethroughStyleAttributeName:@2,//删除线
NSUnderlineStyleAttributeName:@1, //下划线
//行间距
paragraph.lineSpacing = 10;
//段间距
paragraph.paragraphSpacing = 50;
//头尾间距(第一行)
paragraph.firstLineHeadIndent = 50;
计算label高度
CGSize size1 =[string boundingRectWithSize:CGSizeMake(self.view.frame.size.width-40, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
竖直文本Size计算
CGSize size = [string boundingRectWithSize:CGSizeMake(字体大小, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
自适应
+ sizeToFit
+ sizeThatFits:(CGSize)