Created
November 11, 2015 12:33
-
-
Save advantis/f0f61044aca414a41cb1 to your computer and use it in GitHub Desktop.
UIColor hex utilities
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
extension UIColor { | |
convenience init(hexNumber: UInt32) { | |
let red = CGFloat(hexNumber >> 16 & 0xFF) / 255 | |
let green = CGFloat(hexNumber >> 8 & 0xFF) / 255 | |
let blue = CGFloat(hexNumber & 0xFF) / 255 | |
self.init(red: red, green: green, blue: blue, alpha: 1) | |
} | |
convenience init?(hexString: String) { | |
guard let number = UInt32(hexString, radix: 16) else { | |
return nil | |
} | |
self.init(hexNumber: number) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment