views:

40

answers:

1

Can anyone tell me why this colorUsingColorSpaceName is returning nil? For example, the following code block will print "deviceColor is nill":

NSColor *color = [NSColor windowBackgroundColor];
NSColor *deviceColor = [color colorUsingColorSpaceName: NSDeviceRGBColorSpace];
if(deviceColor == nil) NSLog(@"deviceColor is nill");

How can I convert an NSColor in the NSNamedColorSpace? I need to be able to get the color components so i can convert an NSColor to a CGColorRef

+2  A: 

It's too complicated to be expressed as an RGB value. It's a single object that draws differently when the window is active vs inactive. In some cases it's also a pattern color (i.e. a tiled image) rather than a flat fill.

Ken
So how am I supposed to get the right colors for drawing custom ui components with Core Graphics?
Bret
Bret: Use `[NSColor windowBackgroundColor]`. To make a CGColor for it, try this: Get its `patternImage` (and go the RGB-conversion route if it doesn't have one), create a CGImage from the NSImage, create a CGPattern that draws the CGImage, and create a CGColor with that CGPattern.
Peter Hosey