Skip to content

Instantly share code, notes, and snippets.

@GE-N
Last active August 29, 2015 14:24
Show Gist options
  • Save GE-N/097cb5154af7ebaa9a30 to your computer and use it in GitHub Desktop.
Save GE-N/097cb5154af7ebaa9a30 to your computer and use it in GitHub Desktop.
UIColor from Hex Code in Swift
// Inspiration from
// http://stackoverflow.com/questions/28644311/howto-get-the-rgb-code-int-from-an-uicolor-in-swift
// http://stackoverflow.com/questions/24074257/how-to-use-uicolorfromrgb-value-in-swift
func UIColorFromRGB(rgbValue: UInt) -> UIColor {
return UIColor(
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
alpha: CGFloat(1.0))
}
struct ThemedColor {
static let buttonNormalState = UIColor(white: 1, alpha: 0.3)
static let buttonHighlightedState = UIColorFromRGB(0xFEC057)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment