My view overrides the drawRect
method to render graphics
.
And I've recently added a gradient background using CAGradientLayer
and [view.layer insertSubLayer: atIndex:0]
However the CAGradientLayer
gets drawn over my graphics instead of underneath.
Setting alpha of the gradient colours 0.5 shows that my graphics are still being drawn.
This is an app with a high graphics refresh rate, I cannot afford to redraw a gradient on every refresh so was counting on the CAGradientLayer's
backing store to keep things performant.
How should I approach this?
Thank you!
Sublayers are always drawn on top of the base layer, much like subviews are always drawn on top of the base view.
What you could try is work at the superview's level, and add a gradient sublayer to it. It will be displayed below your view.