Skip to content

Instantly share code, notes, and snippets.

@madebyjeffrey
Created November 16, 2010 06:30
Show Gist options
  • Save madebyjeffrey/701522 to your computer and use it in GitHub Desktop.
Save madebyjeffrey/701522 to your computer and use it in GitHub Desktop.
CGColor property for NSColor
// Version 3: Simplified, but still can have an exception thrown in the case of a non-floating point colour space.
@implementation NSColor (CGColor)
@dynamic CGColor;
- (CGColorRef) CGColor
{
CGColorSpaceRef colorspace = [[self colorSpace] CGColorSpace];
const NSInteger nComponents = [self numberOfComponents];
CGFloat components[nComponents];
[self getComponents: components];
CGColorRef c = CGColorCreate(colorspace, components);
return (CGColorRef)[(id)c autorelease];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment