Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UIColor convenience initializer, taking hex as an argument
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
You can’t perform that action at this time.