2
votes

I have a plist file that stores cached colors, it looks like this

<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>

what I want to do is use the 3 values to create a UIColor, the UIColor will change depending on the bundle id, the values are for Red, Green, and Blue

but I'd want the UIColor to change automatically if the bundle id changes, I'm using it as the background color for the banners, and say if I'm on the home screen and get a notification, the background is white, but if I open the Settings app I'd want it to change to the RGB value for com.apple.Preferences from the plist sort of how in iOS 6 the status bar background changes automatically when opening an app to match the UINavigationBar

I used:

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];

I am developing for a jailbroken device

1

1 Answers

0
votes

After you pick up that string from the plist:

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

... Or on older compiler

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

If the question includes something else, it's hard to follow the punctuation