views:

5389

answers:

2

Im creating a color object using the following code.

curView.backgroundColor = [[UIColor alloc] initWithHue:229 saturation:40 brightness:75 alpha:1];

How can I retrieve RGB values from the created color object?

+5  A: 
float* colors = CGColorGetComponents( curView.backgroundColor.CGColor );

These links provide further details:

codelogic
Answer below should have been a comment. Oops.
defmech
Note: this only works for colors in the RGB space. For example, this will not work on [UIColor whiteColor] as that is not in RGB.
Jason
+1  A: 
const float* colors = CGColorGetComponents( curView.backgroundColor.CGColor );

Thanks. I had to add the const at the start of the line as it was generating a warning.

defmech