Last active
June 28, 2017 01:07
-
-
Save sforteln/0c348b290e9ad3936cd5ab582ff8a611 to your computer and use it in GitHub Desktop.
Shorten up UIColor creation
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
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