Skip to content

Instantly share code, notes, and snippets.

@Anatoli-Petrosyants
Created March 19, 2018 13:07
Show Gist options
  • Select an option

  • Save Anatoli-Petrosyants/d1bc9d2b5d71f0137e85440647ecc341 to your computer and use it in GitHub Desktop.

Select an option

Save Anatoli-Petrosyants/d1bc9d2b5d71f0137e85440647ecc341 to your computer and use it in GitHub Desktop.
public extension UIColor {
convenience init(hex: Int, alpha: Double = 1.0) {
let r = CGFloat((hex & 0xFF0000) >> 16) / 255.0
let g = CGFloat((hex & 0x00FF00) >> 8) / 255.0
let b = CGFloat(hex & 0x0000FF) / 255.0
self.init(red: r, green: g, blue: b, alpha: CGFloat(alpha))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment