改变Label中不同位置的字的颜色

//chapterStr大字符串 totalImg需要变色的字符串

//取出想要变得字符串在大字符串的什么地方 NSRange changeRange = [chapterStr rangeOfString:totalImg]; //字显示不同的颜色 NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc]initWithString:chapterStr]; [attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithWhite:0.6 alpha:1] range:changeRange]; [cell.nameLable setAttributedText:attributedStr];
 
原文地址:https://www.cnblogs.com/lxllanou/p/3726213.html