Created
December 20, 2016 19:04
-
-
Save haydenholligan/aca7fcfca2aba1ddf14b47d550760282 to your computer and use it in GitHub Desktop.
Hex (AARRGGBB) -> UIColor init
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
| convenience init(hex: String) { | |
| var rgbValue:UInt32 = 0 | |
| Scanner(string: hex).scanHexInt32(&rgbValue) | |
| self.init(red: CGFloat((rgbValue & 0x00FF0000) >> 16) / 255.0, | |
| green: CGFloat((rgbValue & 0x0000FF00) >> 8) / 255.0, | |
| blue: CGFloat(rgbValue & 0x000000FF) / 255.0, | |
| alpha: CGFloat((rgbValue & 0xFF000000) >> 24) / 255.0) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment