UILabel*label = [[UILabelalloc]initWithFrame:CGRectMake(0,0,self.frame.size.width,self.frame.size.height)];
//使用斜杠n是字体显示为两行
label.text=@"随堂测验\n(学习完成后,开始测试)";
label.font= [UIFontsystemFontOfSize:10];
//使用换行符号切莫忘记写这句
label.numberOfLines=0;
label.textColor= [UIColorhexChangeFloat:@"A5A5A5"];
//利用属性字符串修改字体大小颜色
NSMutableAttributedString*AttributedStr = [[NSMutableAttributedStringalloc]initWithString:label.text];
[AttributedStraddAttribute:NSForegroundColorAttributeName
value:[HuConfigrationuiColorFromString:@"#D3D3D3"]
range:NSMakeRange(0,4)];
[AttributedStraddAttribute:NSFontAttributeName
value:[UIFontcustomFontSize:18]
range:NSMakeRange(0,4)];
//修改行间距
NSMutableParagraphStyle*paragraphStyle = [[NSMutableParagraphStylealloc]init];
[paragraphStylesetLineSpacing:4];
[AttributedStraddAttribute:NSParagraphStyleAttributeName
value:paragraphStyle
range:NSMakeRange(0, [label.textlength])];
label.attributedText= AttributedStr;
label.textAlignment=NSTextAlignmentCenter;
[selfaddSubview:label];
效果图:
网友评论