Created
August 2, 2013 08:32
-
-
Save burczyk/6138352 to your computer and use it in GitHub Desktop.
UIColor shorthand which allows to define colors directly from RGB elements (0-255) instead of floats.
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
#import <UIKit/UIKit.h> | |
@interface UIColor (Shorthand) | |
+ (UIColor*) colorWithR: (unsigned char) r G: (unsigned char) g B: (unsigned char) b A: (float) a; | |
@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
#import "UIColor+Shorthand.h" | |
@implementation UIColor (Shorthand) | |
+ (UIColor*) colorWithR: (unsigned char) r G: (unsigned char) g B: (unsigned char) b A: (float) a { | |
NSAssert(r < 256, @"UIColor R > 255"); | |
NSAssert(g < 256, @"UIColor G > 255"); | |
NSAssert(b < 256, @"UIColor B > 255"); | |
return [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment