Skip to content

Instantly share code, notes, and snippets.

@0xc010d
Created July 2, 2014 23:16
Show Gist options
  • Save 0xc010d/670517342b389a82082f to your computer and use it in GitHub Desktop.
Save 0xc010d/670517342b389a82082f to your computer and use it in GitHub Desktop.
import UIKit
typealias ColorDef = UInt32
extension UIColor {
convenience init(_ colorDef: ColorDef) {
self.init(colorDef: colorDef)
}
convenience init(colorDef: ColorDef) {
self.init(colorDef: colorDef, alpha: 1.0)
}
convenience init(colorDef: ColorDef, alpha: CGFloat) {
let blue = CGFloat(colorDef & 0xff) / CGFloat(255)
let green = CGFloat(colorDef >> 8 & 0xff) / CGFloat(255)
let red = CGFloat(colorDef >> 16 & 0xff) / CGFloat(255)
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