Skip to content

Instantly share code, notes, and snippets.

@haydenholligan
Created December 20, 2016 19:04
Show Gist options
  • Select an option

  • Save haydenholligan/aca7fcfca2aba1ddf14b47d550760282 to your computer and use it in GitHub Desktop.

Select an option

Save haydenholligan/aca7fcfca2aba1ddf14b47d550760282 to your computer and use it in GitHub Desktop.
Hex (AARRGGBB) -> UIColor init
convenience init(hex: String) {
var rgbValue:UInt32 = 0
Scanner(string: hex).scanHexInt32(&rgbValue)
self.init(red: CGFloat((rgbValue & 0x00FF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x0000FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x000000FF) / 255.0,
alpha: CGFloat((rgbValue & 0xFF000000) >> 24) / 255.0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment