iOS(修改某一个字符串属性)

/**

 *str:原字符串

 *strColor:要调整的字符串颜色

 *strFont:要调整字符串的大小

 *index:距离到某个字符串位置为止

 *可以继续增加

 */

-(NSMutableAttributedString *)returnChangeString:(NSString *)str strColor:(UIColor *)strColor strFont:(UIFont *)strFont index:(int)index{

    

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

    NSRange rangel = [[textColor string]rangeOfString:[str substringToIndex:str.length -index]];

    [textColor addAttribute:NSForegroundColorAttributeName value:strColor range:rangel];

    [textColor addAttribute:NSFontAttributeName value:strFont range:rangel];

 

    return textColor;

    

}

你可能感兴趣的:(ios)