Skip to content

Instantly share code, notes, and snippets.

@DevAndArtist
Created May 1, 2017 10:21
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 DevAndArtist/50aa5234757ab6a09aad0bbf0ea7f0cc to your computer and use it in GitHub Desktop.
Save DevAndArtist/50aa5234757ab6a09aad0bbf0ea7f0cc to your computer and use it in GitHub Desktop.
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