1

我有以下代码:

 NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
    [attributes setValue:[UIColor colorWithRed:86.0/255.0 green:134.0/255.0 blue:172.0/255.0 alpha:1.0] forKey:NSForegroundColorAttributeName];

它在 iOS 6 上运行良好,但在 iOS 5 上崩溃了。知道为什么吗?

4

2 回答 2

4

NSForegroundColorAttributeName 仅在 iOS6 中可用。

http://developer.apple.com/library/ios/#Documentation/UIKit/Reference/NSAttributedString_UIKit_Additions/Reference/Reference.html

所有 NSAttributedString 仅适用于 iOS6。

于 2012-10-18T05:53:46.363 回答
2

NSAttributedString UIKit Additions ReferenceNSForegroundColorAttributeName说:

NSForegroundColorAttributeName

该属性的值是一个 UIColor 对象。使用此属性可在渲染期间指定文本的颜色。如果不指定此属性,则文本以黑色呈现。

在 iOS 6.0 及更高版本中可用。

在 NSAttributedString.h 中声明。

所以这个属性只适用于 iOS 6 及更高版本。事实上, NSAttributedString UIKit Additions中的所有内容都是 iOS 6 及更高版本。

于 2012-10-18T06:02:26.693 回答