改变指定位置字符的颜色,代码如下:
NSString *descStr = @"楼主"; NSString *nickStr = [NSString stringWithFormat:@"小仙女%@",descStr]; NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:descStr]; [attrStr addAttribute:NSForegroundColorAttributeName value:MainColor range:[nickStr rangeOfString:descStr]]; self.TopUserInfoV.titleLabs.attributedText = attrStr;
如下图红框: