NSString *contentSrt = [NSString stringWithFormat:@"%@ (%@)",categoryModel.categoryName, categoryModel.phoneCount];
NSRange rang = [contentSrt rangeOfString:categoryModel.categoryName];
NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:contentSrt];
[attStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:53.0/255.0 green:53.0/255.0 blue:53.0/255.0 alpha:1.0] range:NSMakeRange(0, contentSrt.length)];
NSRange lightRang = NSMakeRange(rang.length, contentSrt.length - rang.length);
[attStr addAttribute:NSForegroundColorAttributeName value:[UIColor themeLightGrayColor] range:lightRang]; contentLabel.attributedText = attStr;
contentLabel.highlightedTextColor = [UIColor whiteColor];

label显示不同颜色的字体-LMLPHP

05-12 01:17