![关于NSMutableAttributedString属性字符串的用法]
- 好久没更新博客了,今天随便更新一个关于NSMutableAttributedString的用发,前面项目中接触了属性字符串的部分用法,发现真是好用啊!,以下是部分用法:
NSMutableAttributedString* attributedStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"合计: ¥%.2f",model.goodsCount * model.goodsModel.price]];
NSRange range1 = NSMakeRange(0, 3);
NSRange range2 = NSMakeRange(3, attributedStr.length - 3);
[attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#6c6c6c"] range:range1];
[attributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.f] range:range1];
[attributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18.f] range:range2];
[attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#fc4001"] range:range2];
UILable* label=[ [UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)]];
label.attributedText = attributedStr;