Skip to content

Instantly share code, notes, and snippets.

@aoenth
Created May 28, 2020 19:55
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 aoenth/80483e698b7314dadcd3707a6c55c85c to your computer and use it in GitHub Desktop.
Save aoenth/80483e698b7314dadcd3707a6c55c85c to your computer and use it in GitHub Desktop.
UIColor convenience initializer, taking hex as an argument
import UIKit
extension UIColor {
convenience init(hex: Int) {
let red = CGFloat((hex & 0xFF0000) >> (4 * 4))/0xFF
let green = CGFloat((hex & 0x00FF00) >> (4 * 2))/0xFF
let blue = CGFloat(hex & 0x0000FF)/0xFF
self.init(red: red, green: green, blue: blue, alpha: 1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment