更改字符串颜色(长度不确定,有服务器返回)

            cell.Content.text = [NSString stringWithFormat:@"回复 %@:%@",item.nickname,item.content];

            //将前面一部分字更改为灰色

            NSString *str=cell.Content.text;

            NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:str];

            NSString *str1=item.nickname;

            NSInteger a=str1.length;

            [AttributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:163.0/255 green:163.0/255 blue:163.0/255 alpha:1]  range:NSMakeRange(0, a+4)];

            cell.Content.attributedText = AttributedStr;

posted on 2016-08-16 18:06  yucaijiang  阅读(206)  评论(0编辑  收藏  举报

导航