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];
效果圖: