Created
September 22, 2016 17:07
-
-
Save zackshapiro/59d4adfa881abf65756073a413dc3af5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
extension UIColor { | |
class func fromRGB(rgb: UInt32) -> UIColor { | |
return UIColor( | |
red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0, | |
green: CGFloat((rgb & 0x00FF00) >> 8) / 255.0, | |
blue: CGFloat(rgb & 0x0000FF) / 255.0, | |
alpha: CGFloat(1.0) | |
) | |
} | |
class func eightBitRGBA(rgb: UInt32) -> (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) { | |
return ( | |
red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0, | |
green: CGFloat((rgb & 0x00FF00) >> 8) / 255.0, | |
blue: CGFloat(rgb & 0x0000FF) / 255.0, | |
alpha: CGFloat(1.0) | |
) | |
} | |
func darkerColor(percent : Double) -> UIColor { | |
return colorWithBrightnessFactor(factor: CGFloat(1 - percent)); | |
} | |
func colorWithBrightnessFactor(factor: CGFloat) -> UIColor { | |
var hue: CGFloat = 0 | |
var saturation: CGFloat = 0 | |
var brightness: CGFloat = 0 | |
var alpha: CGFloat = 0 | |
if getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha) { | |
return UIColor(hue: hue, saturation: saturation, brightness: brightness * factor, alpha: alpha) | |
} else { | |
return self; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment