【问题标题】:NSMutableArray from plist key values separated by commaNSMutableArray 来自以逗号分隔的 plist 键值
【发布时间】:2013-01-03 03:14:50
【问题描述】:

我有一个存储缓存颜色的 plist 文件,它看起来像这样

<key>CachedColors</key>
<dict>
    <key>com.Halfbrick.Fruit</key>
    <string>0.00000,0.00000,0.00000</string>
    <key>com.apple.Preferences</key>
    <string>0.28824,0.37059,0.48235</string>
</dict>

我想要做的是使用这 3 个值来创建一个 UIColor,UIColor 将根据捆绑 id 改变,值是红色、绿色和蓝色

但我希望 UIColor 在捆绑 ID 更改时自动更改,我将其用作横幅的背景颜色,并说如果我在主屏幕上并收到通知,则背景是白色,但如果我打开设置应用程序,我希望它从 plist 中更改为 com.apple.Preferences 的 RGB 值,类似于在 iOS 6 中状态栏背景如何在打开应用程序以匹配 UINavigationBar

我用过:

SBApplication *frontApp = [(SpringBoard*)[UIApplication sharedApplication] _accessibilityFrontMostApplication];
NSDictionary *statusBarCachedColors = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/cc.tweak.statuscolor.plist"];
NSString *colorString = [statusBarCachedColors objectForKey:frontApp];
NSArray *components = [colorString componentsSeparatedByString:@","];
UIColor *tintColor = [UIColor colorWithRed:[components[0] floatValue] green:[components[1] floatValue] blue:[components[2] floatValue] alpha:1.0];

我正在为越狱设备开发

【问题讨论】:

    标签: iphone ios5 theos


    【解决方案1】:

    从 plist 中获取该字符串后:

    NSArray *components = [string componentsSeparatedByString:@","];
    UIColor *color = [UIColor colorWithRed:[components[0] floatValue] green:[components[1] floatValue] blue:[components[2] floatValue] alpha:1];
    

    ... 或者在旧的编译器上

    UIColor *color = [UIColor colorWithRed:[[components objectAtIndex:0] floatValue]
                                     green:[[components objectAtIndex:1] floatValue]
                                      blue:[[components objectAtIndex:2] floatValue] alpha:1];
    

    如果问题包含其他内容,则很难遵循标点符号

    【讨论】:

    • 测试后我收到一条错误消息,提示“NSArray”可能无法响应“-floatValue”
    • 我会更新我的 OP,你还需要我用来阅读 plist 的内容吗?
    • 您收到的警告很奇怪...您使用的是哪个版本的 xCode?也许它没有采用数组下标符号?
    • 另外,添加一个断点并打印组件数组的样子(po 组件,在调试器控制台中)
    • 我没有使用 Xcode,我使用的是 Theos,它是越狱设备的开发环境,所以没有调试器控制台
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-06
    • 2021-11-08
    • 2018-07-18
    • 1970-01-01
    • 2015-02-18
    相关资源
    最近更新 更多