下面是代码,被注释掉的是原来的代码,指定颜色不生效。

NSMutableAttributedString *attriString = [[[NSMutableAttributedStringalloc] initWithString:string] autorelease];

    NSRange range;

    range.location = 4;

    range.length = nameString.length;

    [attriString removeAttribute:(NSString *)kCTFontAttributeNamerange:range];

    if ([SYSTEM_VERSION intValue] >= 6.0) {

        [attriString addAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor] range:range];

    }

    else{

        [attriString addAttribute:(NSString *)kCTForegroundColorAttributeNamevalue:(id)[UIColorredColor].CGColorrange:range];

    }

    [attriString addAttribute:(NSString *)kCTFontAttributeNamevalue:(id)[UIFontsystemFontOfSize:15] range:range];

//    [attriString addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:

//                               (id)[UIFont systemFontOfSize:15],(NSString *)kCTFontAttributeName,

//                                (id)RGBCOLOR(0, 255, 255),(NSString *)kCTForegroundColorAttributeName,

//                                nil]

//                         range:range];

    [self.auntName setAttributedText:attriString];

相关文章:

  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2021-08-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-13
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
相关资源
相似解决方案