Created
May 1, 2017 10:21
-
-
Save DevAndArtist/50aa5234757ab6a09aad0bbf0ea7f0cc to your computer and use it in GitHub Desktop.
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
extension UIColor { | |
public var grayscale: UIColor { | |
var (red, green, blue, alpha) = (CGFloat(0), CGFloat(0), CGFloat(0), CGFloat(0)) | |
if self.getRed(&red, green: &green, blue: &blue, alpha: &alpha) { | |
// https://en.wikipedia.org/wiki/Grayscale | |
return UIColor(white: red * 0.299 + green * 0.587 + blue * 0.114, alpha: alpha) | |
} | |
return self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment