4

Is there a way to draw a given UIView (and it's subviews) in greyscale?

I'm trying to take a view hierarchy and make it look disabled without overlaying an image or switching the images used to draw each UIView in the hierarchy.

Quentin
  • 3,971
  • 2
  • 26
  • 29
  • Adding a comment to my old question. There might be a solution in this thread: http://stackoverflow.com/questions/1298867/convert-image-to-grayscale – Quentin Dec 05 '13 at 00:17

3 Answers3

3

Add a CALayer to your UIView, with the compositingFilter set to colorBlendMode:

let grayLayer = CALayer()
grayLayer.frame = bounds
grayLayer.compositingFilter = "colorBlendMode"
grayLayer.backgroundColor = UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1.0).cgColor
layer.addSublayer(grayLayer)
gnewby
  • 31
  • 3
-1

You cannot draw a UIView in grayscale, but you may place a semi-transparent UIView layer on top of the whole thing to show a grayed out behavior.

Check this.

Community
  • 1
  • 1
theunexpected1
  • 1,017
  • 11
  • 23
-1

When I want to disable a view, I usually just set userInteractionEnabled = NO and alpha = .5 (or some other < 1. alpha)

Ben Baron
  • 14,496
  • 12
  • 55
  • 65