Created
November 15, 2016 12:09
-
-
Save oboje/b7b2a663e5cf3103beb7c8c625a0cfb5 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