Created
February 11, 2014 19:20
-
-
Save marcuswestin/8942110 to your computer and use it in GitHub Desktop.
UIColor creators
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
// UIColor* red = rgb(255,0,0); | |
// UIColor* steelblue = [UIColor fromHex:0x4682B4]; | |
// UIColor* shade = rgba(150,150,150,0.5); | |
UIColor* rgba(CGFloat r, CGFloat g, CGFloat b, CGFloat a) { | |
return [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]; | |
} | |
UIColor* rgb(CGFloat r, CGFloat g, CGFloat b) { | |
return rgba(r, g, b, 1.0); | |
} | |
UIColor* hsva(CGFloat h, CGFloat s, CGFloat v, CGFloat a) { | |
return [UIColor colorWithHue:h/360.0 saturation:s/100.0 brightness:v/100.0 alpha:a/100.0]; | |
} | |
UIColor* hsv(CGFloat h, CGFloat s, CGFloat v) { | |
return hsva(h, s, v, 100.0); | |
} | |
@implementation UIColor (Fun) | |
+ (instancetype)colorFromHex:(int)num { | |
return [self colorFromHex:num alpha:1.0]; | |
} | |
+ (instancetype)colorFromHex:(int)num alpha:(CGFloat)alpha { | |
CGFloat r = (num & 0xFF0000) >> 16; | |
CGFloat g = (num & 0x00FF00) >> 8; | |
CGFloat b = (num & 0x0000FF) >> 0; | |
return rgb(r,g,b); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment