-
-
Save leeprobert/5434129 to your computer and use it in GitHub Desktop.
This file contains 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+Hex.h | |
// SoundCloud | |
// | |
// Created by Robert Böhnke on 4/1/11. | |
// Copyright 2011 Soundcloud Ltd. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSColor (Hex) | |
+ (NSColor *)colorWithRGB:(NSUInteger)hex; | |
+ (NSColor *)colorWithDeviceRGB:(NSUInteger)hex; | |
+ (NSColor *)colorWithCalibratedRGB:(NSUInteger)hex; | |
@end |
This file contains 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+Hex.m | |
// SoundCloud | |
// | |
// Created by Robert Böhnke on 4/1/11. | |
// Copyright 2011 Soundcloud Ltd. All rights reserved. | |
// | |
#import "NSColor+Hex.h" | |
@implementation NSColor (Hex) | |
+ (NSColor *)colorWithDeviceRGB:(NSUInteger)hex; | |
{ | |
hex &= 0xFFFFFF; | |
NSUInteger red = (hex & 0xFF0000) >> 16; | |
NSUInteger green = (hex & 0x00FF00) >> 8; | |
NSUInteger blue = hex & 0x0000FF; | |
return [NSColor colorWithDeviceRed:(red / 255.0f) green:(green / 255.0f) blue:(blue / 255.0f) alpha: 1.0]; | |
} | |
+ (NSColor *)colorWithCalibratedRGB:(NSUInteger)hex; | |
{ | |
hex &= 0xFFFFFF; | |
NSUInteger red = (hex & 0xFF0000) >> 16; | |
NSUInteger green = (hex & 0x00FF00) >> 8; | |
NSUInteger blue = hex & 0x0000FF; | |
return [NSColor colorWithCalibratedRed:(red / 255.0f) green:(green / 255.0f) blue:(blue / 255.0f) alpha: 1.0]; | |
} | |
+ (NSColor *)colorWithRGB:(NSUInteger)hex; | |
{ | |
return [NSColor colorWithCalibratedRGB:hex]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment