Created
November 15, 2016 12:09
-
-
Save oboje/61a7cea731ccd5fbd0bbb98455363a29 to your computer and use it in GitHub Desktop.
Obj-C Categories / Helpers
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
| @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