Created
January 20, 2015 07:49
-
-
Save negibouze/ea2a0d9da63b4c1f4790 to your computer and use it in GitHub Desktop.
UIColor with RGB
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
// Pattern A func | |
func rgb(red r: CGFloat, green g: CGFloat, blue b: CGFloat) -> UIColor { | |
return rgba(red: r, green: g, blue: b, alpha: 1.0) | |
} | |
func rgba(red r: CGFloat, green g: CGFloat, blue b: CGFloat, alpha a: CGFloat) -> UIColor { | |
return UIColor(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: a) | |
} | |
// Pattern B Extension | |
extension UIColor { | |
convenience init(r: CGFloat, g: CGFloat, b: CGFloat) { | |
self.init(r: r, g: g, b: b, a: 1.0) | |
} | |
convenience init(r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat) { | |
self.init(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: a); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment