tags:

views:

70

answers:

2

i.e. I want to know the value of blue. How would I get that from an UIColor?

+2  A: 

UIColor class does not provide information about color components. You must get components from its CGColor instead. Note that the number of components depends on color space used in CGColorRef.

This code prints components for blue color:

UIColor* color = [UIColor blueColor];
int n = CGColorGetNumberOfComponents(color.CGColor);
const CGFloat *coms = CGColorGetComponents(color.CGColor);
for (int i = 0; i < n; ++i)
    NSLog(@"%f", coms[i]);
Vladimir
Useful link for more background: http://arstechnica.com/apple/guides/2009/02/iphone-development-accessing-uicolor-components.ars
Jim
A: 

I was just looking up this problem earlier this morning. I don't know why UIColor is so incomplete compared to NSColor. Anyway, I found this useful category for UIColor: Accessing UIColor Components

Dan