Created
May 28, 2020 19:55
-
-
Save aoenth/80483e698b7314dadcd3707a6c55c85c to your computer and use it in GitHub Desktop.
UIColor convenience initializer, taking hex as an argument
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
import UIKit | |
extension UIColor { | |
convenience init(hex: Int) { | |
let red = CGFloat((hex & 0xFF0000) >> (4 * 4))/0xFF | |
let green = CGFloat((hex & 0x00FF00) >> (4 * 2))/0xFF | |
let blue = CGFloat(hex & 0x0000FF)/0xFF | |
self.init(red: red, green: green, blue: blue, alpha: 1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment