Skip to content

Instantly share code, notes, and snippets.

@fwhenin
Created May 14, 2014 18:43
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 fwhenin/9baaeb5d07be5f0fffd4 to your computer and use it in GitHub Desktop.
Save fwhenin/9baaeb5d07be5f0fffd4 to your computer and use it in GitHub Desktop.
Hex to UIColor Method
+(UIColor *)convertToUIColorFromHex:(NSString *) hex{
NSScanner *scanner = [NSScanner scannerWithString:hex];
unsigned int baseColor;
[scanner scanHexInt:&baseColor];
CGFloat red = ((baseColor & 0xFF0000) >> 16) / 255.0f;
CGFloat green = (baseColor & 0x00FF00) >> 8) / 255.0f;
CGFloat blue = (baseColor & 0x0000FF)) / 255.0f;
UIColor *color = [UIColor colorWithRed:red green:green blue:blue alpha:1.0f];
return color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment