ios同一个Label中的字符设置不同的字体

来源:互联网 发布:我国网络零售的特点 编辑:程序博客网 时间:2024/05/18 20:51

NSString* amountStr = @"$12";

NSMutableAttributedString *arrt = [[NSMutableAttributedStringalloc]initWithString:amountStr];

[arrt addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,1)];

[arrt addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(1, amountStr.length-1)];

[arrt addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:18]range:NSMakeRange(0,1)];

[arrt addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:30]range:NSMakeRange(1, amountStr.length-1)];

_amountLabel.attributedText = arrt;

1 0
原创粉丝点击