Created
November 13, 2017 05:35
-
-
Save 0x30/1fa722406a48d6d904e64012d5bee872 to your computer and use it in GitHub Desktop.
UIColor init With hexString
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (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