Last active
July 18, 2017 02:45
-
-
Save Revolucent/ea3959b9175c27ee98cf to your computer and use it in GitHub Desktop.
Convert a six-digit hex literal into a color
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
extension UIColor { | |
convenience init(hex: UInt, alpha: CGFloat = 1.0) { | |
let red = CGFloat((hex & 0xFF0000) >> 0x10) / 255.0 | |
let green = CGFloat((hex & 0x00FF00) >> 0x8) / 255.0 | |
let blue = CGFloat(hex & 0x0000FF) / 255.0 | |
self.init(red: red, green: green, blue: blue, alpha: alpha) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pretty straightforward: