在我的 iPhone 应用程序中,我有一个 appSettings.plist。这让我和其他人可以简单地更改一些参数。其中一个参数是应用程序的主要颜色。.plist 看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Red</key>
<integer>255</integer>
<key>Green</key>
<integer>123</integer>
<key>Blue</key>
<integer>124</integer>
<key>compositeRGB</key>
</dict>
</plist>
在我的代码中,我阅读了这个文件,并尝试用这三个数字制作一个 UIColor。我不得不承认我对 CGFLoats 了解不多,我怀疑这就是我麻烦的原因。这就是我所做的:
-(void)readAppSettings
{
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"appSettings.plist"];
NSDictionary *plistDictionary = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];
unsigned int RedComponent = [[plistDictionary objectForKey:@"Red"]intValue];
unsigned int GreenComponent = [[plistDictionary objectForKey:@"Green"]intValue];
unsigned int BlueComponent = [[plistDictionary objectForKey:@"Blue"]intValue];
appColor = [UIColor colorWithRed: ((float) RedComponent / 255.0f)
green: ((float) GreenComponent / 255.0f)
blue:((float) BlueComponent / 255.0f)
alpha:1.0f];
}
每当我尝试appColor
用作 UIColor 时,我的应用程序就会崩溃,并出现以下错误:
'-[__NSCFArray CGColor]: 无法识别的选择器发送到实例 0x7b0ab20'
Could somebody explain to me what I'm doing wrong. You don't have to be polite.