Skip to content

Instantly share code, notes, and snippets.

@burczyk
Created August 2, 2013 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burczyk/6138352 to your computer and use it in GitHub Desktop.
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.
#import <UIKit/UIKit.h>
@interface UIColor (Shorthand)
+ (UIColor*) colorWithR: (unsigned char) r G: (unsigned char) g B: (unsigned char) b A: (float) a;
@end
#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