zrobiłem kategorię dla tego:
@implementation UIColor (EPPZRepresenter)
NSString *NSStringFromUIColor(UIColor *color)
{
const CGFloat *components = CGColorGetComponents(color.CGColor);
return [NSString stringWithFormat:@"[%f, %f, %f, %f]",
components[0],
components[1],
components[2],
components[3]];
}
UIColor *UIColorFromNSString(NSString *string)
{
NSString *componentsString = [[string stringByReplacingOccurrencesOfString:@"[" withString:@""] stringByReplacingOccurrencesOfString:@"]" withString:@""];
NSArray *components = [componentsString componentsSeparatedByString:@", "];
return [UIColor colorWithRed:[(NSString*)components[0] floatValue]
green:[(NSString*)components[1] floatValue]
blue:[(NSString*)components[2] floatValue]
alpha:[(NSString*)components[3] floatValue]];
}
@end
tego samego formatowania, który jest używany przez NSStringFromCGAffineTransform. W rzeczywistości jest to część większego obiektu reprezentującego obiekty plist w [eppz! Kit w GitHub] [1].
Wystarczy pamiętać, że czerwone, zielone, niebieskie wartości 0.0-1.0 nie 0-255 więc podzielić je przez 255, aby uzyskać prawidłową wartość - to chwycił mnie na chwilę. – amergin
To jest do przechowywania w 'plist', prawdopodobnie chcesz" zaprojektować "kolory w' plist'. Pomocy do konwersji RGB można znaleźć na stronie http://stackoverflow.com/questions/13224206/how-do-i-create-an-rgb-color-with-uicolor/21297254#21297254 oraz http://stackoverflow.com/questions/ 437113/how-to-get-rgb-values-from-uicolor/21296829 # 21296829. – Geri