当前位置: 代码迷 >> 综合 >> ios NSMutableAttributedString 实现富文本(不同颜色字体、下划线等)
  详细解决方案

ios NSMutableAttributedString 实现富文本(不同颜色字体、下划线等)

热度:86   发布时间:2023-12-15 01:53:17.0

效果图:


- (void)setLabText:(NSString *)text
{NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:text];[attributedStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16],NSForegroundColorAttributeName:COLOR_252525} range:NSMakeRange(0, 4)];[attributedStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:COLOR_0093FF} range:NSMakeRange(4, text.length-5)];[attributedStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:COLOR_999999} range:NSMakeRange(text.length-2, 2)];_Lab.attributedText = attributedStr;
}