NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"123"];
[string addAttribute:(NSString *)NSForegroundColorAttributeName value:(id)[UIColor redColor].CGColor range:NSMakeRange(1, 1)];
我们在使用NSMutableAttributedString设置文本颜色时,在iOS8上使用上述的方法会造成崩溃,抛出的异常如下:
解决方法是将.CGColor去掉即可,即:
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"123"];
[string addAttribute:(NSString *)NSForegroundColorAttributeName value:(id)[UIColor redColor] range:NSMakeRange(1, 1)];