美文网首页
NSMutableAttributedString在iOS8上崩

NSMutableAttributedString在iOS8上崩

作者: 我是一个TableView | 来源:发表于2016-08-05 11:30 被阅读0次
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"123"];

[string addAttribute:(NSString *)NSForegroundColorAttributeName value:(id)[UIColor redColor].CGColor range:NSMakeRange(1, 1)];

我们在使用NSMutableAttributedString设置文本颜色时,在iOS8上使用上述的方法会造成崩溃,抛出的异常如下:

8D0A0E0F-EDAA-4A5A-924D-094FAA62B909.png

解决方法是将.CGColor去掉即可,即:

NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"123"];

[string addAttribute:(NSString *)NSForegroundColorAttributeName value:(id)[UIColor redColor] range:NSMakeRange(1, 1)];

相关文章

网友评论

      本文标题:NSMutableAttributedString在iOS8上崩

      本文链接:https://www.haomeiwen.com/subject/zmphsttx.html