下面是代码,被注释掉的是原来的代码,指定颜色不生效。
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];