我想从我的plist中检索一个UIColor字典,但在做这件事时遇到了一些麻烦。从Plist中检索颜色。 iOS
我将我的UIColors添加到字典中的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;
}
但是,由于颜色被字符串拾取,显然会导致崩溃。
并将其作为一个字符串十六进制值 – CW0007007 2015-02-23 13:17:22
'UIColor'情况下不能直接存储到属性列表。只有'NSNumber','NSString','NSData','NSDate'和(可能是嵌套的)字典/数组的实例。 – 2016-10-18 02:05:11