Created
November 7, 2017 15:29
-
-
Save rodydavis/58f15bd3c30550c0d9dc9112cfffa6c5 to your computer and use it in GitHub Desktop.
Making new UIColors easier
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 to make it easy for UIColor init | |
extension UIColor { | |
convenience init(red: Int, green: Int, blue: Int) { | |
let newRed = CGFloat(red)/255 | |
let newGreen = CGFloat(green)/255 | |
let newBlue = CGFloat(blue)/255 | |
self.init(red: newRed, green: newGreen, blue: newBlue, alpha: 1.0) | |
} | |
} | |
//With the extension | |
let newSwiftColor = UIColor(red: 255, green: 165, blue: 0) | |
//With fancy Swift Numeric Literals | |
let fancySwiftColor = UIColor(red: 0xFF, green: 0xA5, blue: 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment