开发者

storing uicolor in plist

I am trying to store UIColor 开发者_如何学Pythonin plist.I seen many links but none of those not given accurate answer.some of my sample code is below

CGColorRef color=[MyColor CGColor];
NSUInteger numComponents = CGColorGetNumberOfComponents(color);
const CGFloat *components=CGColorGetComponents(color);

NSArray *colorArray=[NSArray arrayWithObjects:(float)components[0],(float)components[1],nil];

it is giving Not working for me can any one tell me the exact answer to store uicolor into plist.Thanks in advance.Your suggestion is important for me.Please provide sample snippet rather than posting links.


You would need to store the individual colors separately (RGBA, if that is the color space you are using) in an array of NSNumbers.

NSNumber *red = [NSNumber numberWithFloat:components[0]];
NSNumber *green = [NSNumber numberWithFloat:components[1]];
NSNumber *blue = [NSNumber numberWithFloat:components[2]];
NSNumber *alpha = [NSNumber numberWithFloat:components[3]];

NSArray *colors = [NSArray arrayWithObjects:red, green, blue, alpha, nil];

The reason for this is that you can only add objects to a NSArray. A float or CGFloat is not an object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜