Skip to content

Instantly share code, notes, and snippets.

@rodydavis
Created November 7, 2017 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodydavis/58f15bd3c30550c0d9dc9112cfffa6c5 to your computer and use it in GitHub Desktop.
Save rodydavis/58f15bd3c30550c0d9dc9112cfffa6c5 to your computer and use it in GitHub Desktop.
Making new UIColors easier
//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