Created
November 20, 2010 16:11
-
-
Save msanders/707921 to your computer and use it in GitHub Desktop.
Category for AppKit that converts an NSColor to a CGColor (ala UIColor in the iOS)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSColor+CGColor.m | |
// | |
// Created by Michael Sanders on 11/19/10. | |
// | |
#import <AppKit/AppKit.h> | |
@interface NSColor (CGColor) | |
// | |
// The Quartz color reference that corresponds to the receiver's color. | |
// | |
@property (nonatomic, readonly) CGColorRef CGColor; | |
// | |
// Converts a Quartz color reference to its NSColor equivalent. | |
// | |
+ (NSColor *)colorWithCGColor:(CGColorRef)color; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSColor+CGColor.m | |
// | |
// Created by Michael Sanders on 11/19/10. | |
// | |
#import "NSColor+CGColor.h" | |
@implementation NSColor (CGColor) | |
- (CGColorRef)CGColor | |
{ | |
const NSInteger numberOfComponents = [self numberOfComponents]; | |
CGFloat components[numberOfComponents]; | |
CGColorSpaceRef colorSpace = [[self colorSpace] CGColorSpace]; | |
[self getComponents:(CGFloat *)&components]; | |
return (CGColorRef)[(id)CGColorCreate(colorSpace, components) autorelease]; | |
} | |
+ (NSColor *)colorWithCGColor:(CGColorRef)CGColor | |
{ | |
if (CGColor == NULL) return nil; | |
return [NSColor colorWithCIColor:[CIColor colorWithCGColor:CGColor]]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how can we use this with ARC?