NSMutableAttributing相关 ios7升级ios8出现的问题

项目在ios7上没有问题,但是升级ios8以后,出现了不少问题,其中一个追踪到就是在NSMutableAttributing的使用上出现的问题。

项目中有个功能是:有一串字符串,对指定位置的字符设置不同的颜色,就是使用NSMutableAttributedString来实现的:

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

[attibuttionStr addAttribute:(NSString *)NSForegroundColorAttributeName

                           value:(id)firstColor.CGColor

                           range:oneRange];

在ios7上这样是能正常实现的

但是ios8上除了问题,程序崩溃,提示“

2014-09-23 13:30:50.224 RecordForStudy[17993:413448] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType set]: unrecognized selector sent to instance 0x7fcbcba07090'

最终找出,

在ios8上用value:(id)firstColor.CGColor就会报错,

改成value:(id)firstColor就好了。

[attibuttionStr addAttribute:(NSString *)NSForegroundColorAttributeName

                           value:(id)firstColor

                           range:oneRange];

这样就好了。

总结:在ios7以及之前,value的值写

1、(id)firstColor.CGColor

或者直接写

2、(id)firstColor

都是没问题的,

但是在ios8上只能写成2、(id)firstColor这种样式才是正确的

转载于:https://www.cnblogs.com/guatiantian/p/3988184.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值