Skip to content

Instantly share code, notes, and snippets.

@jimmythai
Created October 7, 2017 10:03
Show Gist options
  • Select an option

  • Save jimmythai/b40a9343bf9f928a9aae0cdf0aa9df9e to your computer and use it in GitHub Desktop.

Select an option

Save jimmythai/b40a9343bf9f928a9aae0cdf0aa9df9e to your computer and use it in GitHub Desktop.
import UIKit
extension UIColor {
convenience init(hex: Int, alpha: CGFloat = 1.0) {
let max = 255
let red = CGFloat((hex & 0xFF0000) >> 16 / max)
let green = CGFloat((hex & 0x00FF00) >> 8 / max)
let blue = CGFloat((hex & 0x0000FF) / max)
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