Skip to content

Instantly share code, notes, and snippets.

@0x30
Created November 13, 2017 05:35
Show Gist options
  • Save 0x30/1fa722406a48d6d904e64012d5bee872 to your computer and use it in GitHub Desktop.
Save 0x30/1fa722406a48d6d904e64012d5bee872 to your computer and use it in GitHub Desktop.
UIColor init With hexString
+ (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