ios 一个Label显示多行不同字体的文字

`UILabel *lbl = [[UILabel alloc]init];

NSString *text =@"你好\n哈哈哈";
NSMutableAttributedString *attributeText = [[NSMutableAttributedString alloc]initWithString:text];
[attributeText addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17]  range:NSMakeRange(0, text.length)];
[attributeText addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, text.length)];
[attributeText addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:24] range:NSMakeRange(3, 3)];
[attributeText addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(3, text.length - 3)];
lbl.attributedText = attributeText;
lbl.numberOfLines = 0;
lbl.textAlignment = NSTextAlignmentCenter;
lbl.frame = CGRectMake(0, 200, 100, 100);
[self.view addSubview:lbl];
`
上一篇:BeeWare 峰器 中文文档 - 教程 5 - 移动端:iOS


下一篇:iPhone卡在Apple 徽标、黑屏、冻结屏幕怎么办?