简体   繁体   中英

NSMutableDictionary setting value crashes on iOS 5

I have the following code:

 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];

it works just fine on iOS 6, but it crashed on iOS 5. Any idea why?

NSForegroundColorAttributeName is available in iOS6 only.

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

All of NSAttributedString is iOS6 only.

The NSAttributedString UIKit Additions Reference for NSForegroundColorAttributeName says:

NSForegroundColorAttributeName

The value of this attribute is a UIColor object. Use this attribute to specify the color of the text during rendering. If you do not specify this attribute, the text is rendered in black.

Available in iOS 6.0 and later.

Declared in NSAttributedString.h.

So this attribute is only available in iOS 6 and later. In fact everything in the NSAttributedString UIKit Additions is iOS 6 and later.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM