Skip to content

Instantly share code, notes, and snippets.

@reejosamuel
Created October 16, 2017 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reejosamuel/2ab22f6a8e0b899e31c4db4ee2392af1 to your computer and use it in GitHub Desktop.
Save reejosamuel/2ab22f6a8e0b899e31c4db4ee2392af1 to your computer and use it in GitHub Desktop.
UIColor extensions for hex color
extension UIColor {
public convenience init(hex: UInt32) {
let mask = 0x000000FF
let r = Int(hex >> 16) & mask
let g = Int(hex >> 8) & mask
let b = Int(hex) & mask
let red = CGFloat(r) / 255
let green = CGFloat(g) / 255
let blue = CGFloat(b) / 255
self.init(red:red, green:green, blue:blue, alpha:1)
}
public class var background: UIColor { return UIColor(hex: 0x000000) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment