我想从我的plist字典中检索出一个UIColor,但是在这方面遇到了一些麻烦。
我将我的UIColor添加到我的plist字典中,然后在字符串中添加。(请参见附图)
我在我的plist中像这样保存它们:
[UIColor colorWithRed:57/255.0 green:131/255.0 blue:50/255.0 alpha:1]
然后我有一个文件,里面保存了我所有的颜色,例如:
+ (instancetype)titleBarColor
{
return [UIColor colorWithRed:57/255.0 green:131/255.0 blue:50/255.0 alpha:1];
}
但我想做类似于以下内容的事情:
+ (instancetype)titleBarColor
{
NSBundle* settings = [NSBundle mainBundle];
NSMutableDictionary *testing = [settings objectForInfoDictionaryKey: @"appColours"];
UIColor *test = [testing objectForKey:@"titleBarColor"];
NSLog(@"Test Colour %@", test);
return test;
}
但显然会因为颜色被字符串捕捉而崩溃。
UIColor
实例不能直接存储到属性列表中。只能存储NSNumber
、NSString
、NSData
、NSDate
实例以及(可能嵌套的)这些实例的字典/数组。 - Nicolas Miari