Created
July 18, 2016 19:42
-
-
Save ramakser/adec669d01fc7f69671631ec6875e6d5 to your computer and use it in GitHub Desktop.
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
extension UIColor { | |
convenience init(red: Int, green: Int, blue: Int) { | |
assert(red >= 0 && red <= 255, "Invalid red component") | |
assert(green >= 0 && green <= 255, "Invalid green component") | |
assert(blue >= 0 && blue <= 255, "Invalid blue component") | |
self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0) | |
} | |
convenience init(netHex:Int) { | |
self.init(red:(netHex >> 16) & 0xff, green:(netHex >> 8) & 0xff, blue:netHex & 0xff) | |
} | |
} | |
Usage: | |
var color = UIColor(red: 0xFF, green: 0xFF, blue: 0xFF) | |
var color2 = UIColor(netHex:0xFFFFFF) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment