Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load a UIColor from a Plist

Tags:

ios

ios4

Regarding saving the UIColor in a Plist: I have tried different ways but not been able to do so, I want to save and retrieve the color values in a plist file.

I can not extract the data value of the color using nslog and save it in the plist.

Is there any other way to do so?

like image 584
N.K Avatar asked Dec 15 '10 04:12

N.K


1 Answers

I prefer using string to store the color. The parsing code that does this shown below (cut out from https://github.com/xslim/TKThemeManager/blob/master/TKThemeManager.m#L162)

+ (UIColor *)colorFromString:(NSString *)hexString {    
    NSScanner *scanner = [NSScanner scannerWithString:hexString];
    unsigned hex;
    BOOL success = [scanner scanHexInt:&hex];

    if (!success) return nil;
    if ([hexString length] <= 6) {
        return UIColorFromRGB(hex);
    } else {
        unsigned color = (hex & 0xFFFFFF00) >> 8;
        CGFloat alpha = 1.0 * (hex & 0xFF) / 255.0;
        return UIColorFromRGBA(color, alpha);
    }
}
like image 79
Taras Kalapun Avatar answered Oct 14 '22 14:10

Taras Kalapun