Skip to content

Instantly share code, notes, and snippets.

@Isabellle
Last active November 21, 2016 15:58
Show Gist options
  • Save Isabellle/435e25c6a0650aeedb73336f350c6b97 to your computer and use it in GitHub Desktop.
Save Isabellle/435e25c6a0650aeedb73336f350c6b97 to your computer and use it in GitHub Desktop.
Swift - method to set hex to UIColor
func UIColorFromHex(rgbValue:UInt32, alpha:Double=1.0)->UIColor {
let red = CGFloat((rgbValue & 0xFF0000) >> 16)/256.0
let green = CGFloat((rgbValue & 0xFF00) >> 8)/256.0
let blue = CGFloat(rgbValue & 0xFF)/256.0
return UIColor(red:red, green:green, blue:blue, alpha:CGFloat(alpha))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment