【发布时间】:2015-04-24 19:53:24
【问题描述】:
我正在尝试从字典中的 plist 中检索 UIColor,但在执行此操作时遇到了一些问题。
我在字典中的 plist 中添加了 UIColors,然后在字符串中添加。 (见附图)
我将它们保存在我的 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和(可能是嵌套的)字典/数组的实例。
标签: ios xcode dictionary plist uicolor