私の iPhone アプリには、appSettings.plist があります。これにより、私だけでなく、他の人もいくつかのパラメーターを簡単に変更できます。パラメーターの 1 つは、アプリの主な色です。.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>
私のコードでは、このファイルを読み取り、これら 3 つの数値から 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];
}
UIColor として使用しようとするappColor
と、アプリがクラッシュし、次のエラーが表示されます。
'-[__NSCFArray CGColor]: 認識されないセレクターがインスタンス 0x7b0ab20 に送信されました'
Could somebody explain to me what I'm doing wrong. You don't have to be polite.