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.
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.
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)
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.
When I want to disable a view, I usually just set userInteractionEnabled = NO
and alpha = .5
(or some other < 1. alpha)