Skip to content

Instantly share code, notes, and snippets.

@sforteln
Last active June 28, 2017 01:07
Show Gist options
  • Save sforteln/0c348b290e9ad3936cd5ab582ff8a611 to your computer and use it in GitHub Desktop.
Save sforteln/0c348b290e9ad3936cd5ab582ff8a611 to your computer and use it in GitHub Desktop.
Shorten up UIColor creation
import UIKit
extension UIColor {
class func rgb(_ red: Int, _ green: Int, _ blue: Int) -> UIColor {
return UIColor.rgba(red,green,blue,1.0)
}
class func rgba(_ red: Int, _ green: Int, _ blue: Int, _ alpha: Float) -> UIColor {
return UIColor.init(colorLiteralRed: Float(red)/255.0, green: Float(green)/255.0, blue: Float(blue)/255.0, alpha:alpha)
}
}
//example
let green = UIColor.rgba(139,195,74,1.0)
let green = UIColor.rgb(139,195,74)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment