Skip to content

Instantly share code, notes, and snippets.

@alsedi
Created November 15, 2015 19:26
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 alsedi/b845523c6bbe49eb75db to your computer and use it in GitHub Desktop.
Save alsedi/b845523c6bbe49eb75db to your computer and use it in GitHub Desktop.
Shorthand to create UIColor from Int values 0-255
import Foundation
import UIKit
extension UIColor {
static func RGBA(r:Int, _ g: Int, _ b:Int, _ a:Int) -> UIColor {
return UIColor(red: CGFloat(r)/255.0, green: CGFloat(g)/255.0, blue: CGFloat(b)/255.0, alpha: CGFloat(a)/100.0)
}
static func RGB(r:Int, _ g: Int, _ b:Int) -> UIColor {
return UIColor.RGBA(r, g, b, 100)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment