Skip to content

Instantly share code, notes, and snippets.

@evgeniyd
Created December 16, 2014 02:10
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 evgeniyd/667cd101c700c85c72df to your computer and use it in GitHub Desktop.
Save evgeniyd/667cd101c700c85c72df to your computer and use it in GitHub Desktop.
A shorthand for creating UIColor object from components
import UIKit
extension UIColor {
class func colorWithComponents(red redComponent: Float, green: Float, blue: Float, alpha: Float) -> UIColor {
let r: CGFloat = CGFloat(redComponent/255.0)
let g: CGFloat = CGFloat(green/255.0)
let b: CGFloat = CGFloat(blue/255.0)
let a: CGFloat = CGFloat(alpha)
return UIColor(red: r, green: g, blue: b, alpha: a)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment