Skip to content

Instantly share code, notes, and snippets.

@advantis
Created November 11, 2015 12:33
Show Gist options
  • Save advantis/f0f61044aca414a41cb1 to your computer and use it in GitHub Desktop.
Save advantis/f0f61044aca414a41cb1 to your computer and use it in GitHub Desktop.
UIColor hex utilities
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