Search code examples
objective-cplistuicolor

Store and get UIColor from .plist file


I've been searching for this for a while now with no success. My question is: is there an easy way to store and get UIColors such as [UIColor blackColor] or [UIColor colorWithRed:0.38 green:0.757 blue:1 alpha:1]; in a .plist file in my app directory?


Solution

  • according to this discussion you have two options:

    1. Store it like NSData in Data field of .plist file
    2. Store it like String UIColor representation

    NSData option

    NSData *theData = [NSKeyedArchiver archivedDataWithRootObject:[UIColor greenColor]];
    

    NSString option

    NSString *color = @"greenColor";
    [UIColor performSelector:NSSelectorFromString(color)]
    

    read more here: http://www.iphonedevsdk.com/forum/iphone-sdk-development/27335-setting-uicolor-plist.html