Skip to content

Instantly share code, notes, and snippets.

@chockenberry
Created August 7, 2016 18:05
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chockenberry/2431b40049d6a3618c3766852b4e4b34 to your computer and use it in GitHub Desktop.
Save chockenberry/2431b40049d6a3618c3766852b4e4b34 to your computer and use it in GitHub Desktop.
// Created by Sean Heber on 4/12/12.
#import <UIKit/UIKit.h>
// If you work with a designer who specifies color in sRGB using 102,0,204, this category makes it simpler to instantiate
// a color with that specification: [UIColor colorWithRGB:102:0:204 alpha:1.0];
@interface UIColor (RGB)
// NOTE: If you're using the extended sRGB color space, you'll want to use something other than UInt8 :-)
+ (UIColor *)colorWithRGB:(UInt8)r :(UInt8)g :(UInt8)b alpha:(CGFloat)alpha;
@end
@implementation UIColor (RGB)
+ (UIColor *)colorWithRGB:(UInt8)r :(UInt8)g :(UInt8)b alpha:(CGFloat)alpha
{
return [self colorWithRed:r/255.f green:g/255.f blue:b/255.f alpha:alpha];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment