Skip to content

Instantly share code, notes, and snippets.

@oboje
Created November 15, 2016 12:09
Show Gist options
  • Save oboje/61a7cea731ccd5fbd0bbb98455363a29 to your computer and use it in GitHub Desktop.
Save oboje/61a7cea731ccd5fbd0bbb98455363a29 to your computer and use it in GitHub Desktop.
Obj-C Categories / Helpers
@interface Tools: NSObject
+ (UIColor *)colorWithHex:(NSUInteger)hex;
@end
@implementation Tools
+ (UIColor *)colorWithHex:(NSUInteger)hex
{
CGFloat red, green, blue, alpha;`
red = ((CGFloat)((hex >> 16) & 0xFF)) / ((CGFloat)0xFF);
green = ((CGFloat)((hex >> 8) & 0xFF)) / ((CGFloat)0xFF);
blue = ((CGFloat)((hex >> 0) & 0xFF)) / ((CGFloat)0xFF);
alpha = hex > 0xFFFFFF ? ((CGFloat)((hex >> 24) & 0xFF)) / ((CGFloat)0xFF) : 1;
return [UIColor colorWithRed: red green:green blue:blue alpha:alpha];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment