Skip to content

Instantly share code, notes, and snippets.

@PeteGabriel
Created June 17, 2018 14:05
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 PeteGabriel/ee29b1f76df889e9e6bf74012eeaa7c3 to your computer and use it in GitHub Desktop.
Save PeteGabriel/ee29b1f76df889e9e6bf74012eeaa7c3 to your computer and use it in GitHub Desktop.
Create an UIColor from HEX values
extension UIColor {
convenience init(rgb:UInt, alpha:CGFloat = 1.0) {
self.init(
red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgb & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgb & 0x0000FF) / 255.0,
alpha: CGFloat(alpha)
)
}
}
// UIColor(rgb: 0x808080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment