Created
July 29, 2020 10:26
-
-
Save trilliwon/fd80473e8398ff5f163baa00a42babdf to your computer and use it in GitHub Desktop.
Construct UIColor instance from hex value
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 { | |
/// UIColor(hex: 0x000000) | |
convenience init(hex: Int, alpha: CGFloat = 1) { | |
let r = CGFloat((hex & 0xFF0000) >> 16) / 255 | |
let g = CGFloat((hex & 0xFF00) >> 8) / 255 | |
let b = CGFloat((hex & 0xFF)) / 255 | |
self.init(red: r, green: g, blue: b, alpha: alpha) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment