Created
February 1, 2012 13:52
-
-
Save TomLiu/1717023 to your computer and use it in GitHub Desktop.
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+Hex.h | |
// | |
// Created by 61 on 2/1/12. | |
// Copyright (c) 2012 __MyCompanyName__. All rights reserved. | |
// | |
#import <AppKit/AppKit.h> | |
@interface NSColor (Hex) | |
+ (NSColor*)colorWithHex:(NSInteger)hexValue alpha:(CGFloat)alphaValue; | |
+ (NSColor*)colorWithHex:(NSInteger)hexValue; | |
+ (NSColor*)whiteColorWithAlpha:(CGFloat)alphaValue; | |
+ (NSColor*)blackColorWithAlpha:(CGFloat)alphaValue; | |
@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+Hex.m | |
// | |
// Created by 61 on 2/1/12. | |
// Copyright (c) 2012 __MyCompanyName__. All rights reserved. | |
// | |
#import "NSColor+Hex.h" | |
@implementation NSObject (NSColor) | |
+ (NSColor*)colorWithHex:(NSInteger)hexValue alpha:(CGFloat)alphaValue | |
{ | |
return [NSColor colorWithDeviceRed:((float)((hexValue & 0xFF0000) >> 16))/255.0 green:((float)((hexValue & 0xFF00) >> 8))/255.0 blue:((float)(hexValue & 0xFF))/255.0 alpha:alphaValue]; | |
} | |
+ (NSColor*)colorWithHex:(NSInteger)hexValue | |
{ | |
return [NSColor colorWithHex:hexValue alpha:1.0]; | |
} | |
+ (NSColor*)whiteColorWithAlpha:(CGFloat)alphaValue | |
{ | |
return [NSColor colorWithHex:0xffffff alpha:alphaValue]; | |
} | |
+ (NSColor*)blackColorWithAlpha:(CGFloat)alphaValue | |
{ | |
return [NSColor colorWithHex:0x000000 alpha:alphaValue]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment