ios中label富⽂本的设置1.修改不同⽂字和颜⾊
// 创建⼀个富⽂本
NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@"哈哈哈哈哈123456789"]; // 修改富⽂本中的不同⽂字的样式
[attri addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0, 5)];
[attri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 5)];
// 设置数字为红⾊
[attri addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(5, 9)];
[attri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(5, 9)];
2,添加图⽚
// 添加表情
NSTextAttachment *attch = [[NSTextAttachment alloc] init];
// 表情图⽚
attch.image = [UIImage imageNamed:@"d_aini"];
// 设置图⽚⼤⼩
attch.bounds = CGRectMake(0, 0, 32, 32);
// 创建带有图⽚的富⽂本
NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
[attri appendAttributedString:string];
//
attri是上⾯定义的对象
// ⽤label的attributedText属性来使⽤富⽂本 lf.textLabel.attributedText = attri;