Created
May 14, 2014 18:43
-
-
Save fwhenin/9baaeb5d07be5f0fffd4 to your computer and use it in GitHub Desktop.
Hex to UIColor Method
This file contains hidden or 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 *)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