UIColor *color = value;
const CGFloat *components = CGColorGetComponents(color.CGColor);
NSString *colorAsString = [NSString stringWithFormat:@"%f,%f,%f,%f", components[0], components[1], components[2], components[3]];
Fatto.
Se si desidera convertire la stringa di nuovo a un oggetto UIColor:
NSArray *components = [colorAsString componentsSeparatedByString:@","];
CGFloat r = [[components objectAtIndex:0] floatValue];
CGFloat g = [[components objectAtIndex:1] floatValue];
CGFloat b = [[components objectAtIndex:2] floatValue];
CGFloat a = [[components objectAtIndex:3] floatValue];
UIColor *color = [UIColor colorWithRed:r green:g blue:b alpha:a];
State memorizzazione di un oggetto UIColor come un attributo in Core Data? Se è così, date un'occhiata al mio risposta a questa domanda: Core Data data model: attribute type for UIColor
fonte
2010-07-03 17:52:59
Quale formato si desidera che il risultante NSString di avere? Che cosa hai intenzione di fare con quella stringa? (Visualizza per utente, salva in file, ...) –
hi, ad esempio ... whiteColor .. Voglio convertirlo in stringa Tipo di dati ..... @ "whiteColor" ...? –
voglio convertire in UTF8String ..? Qualche aiuto ..? –