将一个字符串分多种颜色显示

//将一个字符串分两种颜色
-(NSMutableAttributedString*)changeStrColor:(NSString *)string{
    NSMutableAttributedString *str = [[NSMutableAttributedStringalloc]initWithString:string];
    [str addAttribute:NSForegroundColorAttributeNamevalue:[UIColorblackColor]range:NSMakeRange(0,3)];
    [str addAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor]range:NSMakeRange(4,string.length -4)];

    return str;
}


你可能感兴趣的:(将一个字符串分多种颜色显示)