UIColor extensions
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
// | |
// UIColor+Utilities.h | |
// | |
// ref: | |
// https://gist.github.com/1219029 | |
// | |
#import <UIKit/UIKit.h> | |
@interface UIColor (Utilities) | |
/* | |
[UIColor colorWithRGBHex:0xff0000]; // red | |
[UIColor colorWithRGBAHex:0x00ff00ff]; // green | |
[UIColor colorWithRGBAHex:0x0000FF80]; // translucent blue | |
*/ | |
+ (UIColor *) colorWithRGBHex:(uint) hex; | |
+ (UIColor *) colorWithRGBAHex:(uint) 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
// | |
// UIColor+Utilities.m | |
// | |
#import "UIColor+Utilities.h" | |
@implementation UIColor (Utilities) | |
+ (UIColor *) colorWithRGBHex:(uint) hex | |
{ | |
int red, green, blue; | |
blue = hex & 0xFF; | |
green = (hex >> 8) & 0xFF; | |
red = (hex >> 16) & 0xFF; | |
return [UIColor colorWithRed:red / 255.0 | |
green:green / 255.0 | |
blue:blue / 255.0 | |
alpha:1.0]; | |
} | |
+ (UIColor *) colorWithRGBAHex:(uint) hex | |
{ | |
int red, green, blue, alpha; | |
alpha = hex & 0xFF; | |
blue = (hex >> 8) & 0xFF; | |
green = (hex >> 16) & 0xFF; | |
red = (hex >> 24) & 0xFF; | |
return [UIColor colorWithRed:red / 255.0f | |
green:green / 255.0f | |
blue:blue / 255.0f | |
alpha:alpha / 255.0f]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment