Last active
August 29, 2015 14:24
-
-
Save GE-N/097cb5154af7ebaa9a30 to your computer and use it in GitHub Desktop.
UIColor from Hex Code in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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