Skip to content

Instantly share code, notes, and snippets.

@arkilis
Created April 21, 2017 22:36
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 arkilis/a52403cbb327b1b2a5890683ec591e8a to your computer and use it in GitHub Desktop.
Save arkilis/a52403cbb327b1b2a5890683ec591e8a to your computer and use it in GitHub Desktop.
UIColor+HexColor.m
+ (UIColor *)colorFromHexString:(NSString *)hexString {
unsigned rgbValue = 0;
NSScanner *scanner = [NSScanner scannerWithString:hexString];
[scanner setScanLocation:1]; // bypass '#' character
[scanner scanHexInt:&rgbValue];
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment