I have a UIView / CALayer which I would like to darken. How can I as fast as possible darken it? Is there any way to avoid blending?
Following alternatives is known to me
- create a non-opaque CALayer and set background color and opacity and add it as a sublayer above main layer
- same as above using UIView (can be a tad slower...?)
- render view/layer to UIImage and doing drawing with CoreGraphics (is way too slow and content is dynamic/changing)
Create a non-opaque CALayer and set background color and opacity and add it as a sublayer above main layer
Someone gave me a tip to have a dark background on the superview/superlayer and set an alpha of the view I want to darken. That way I don't need to add an extra layer/view.
The potential drawback with this is that the view you want to darken will be offscreen rendered if groupview opacity is on (on by default on iOS 7 and above).
I had to do something like this. For anyone curious for the actual code: