Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Created February 8, 2013 16:56
Show Gist options
  • Select an option

  • Save jcromartie/4740350 to your computer and use it in GitHub Desktop.

Select an option

Save jcromartie/4740350 to your computer and use it in GitHub Desktop.
@implementation UIColor (strings)
+ (UIColor *)colorFromRGBHexString:(NSString *)colorString
{
if (colorString.length == 7) {
const char *colorUTF8String = [colorString UTF8String];
int r, g, b;
sscanf(colorUTF8String, "#%2x%2x%2x", &r, &g, &b);
return [UIColor colorWithRed:(r / 255.0) green:(g / 255.0) blue:(b / 255.0) alpha:1.0];
}
return nil;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment