I know CAGradientLayer
doesn't support radial gradient at the moment and only has option of kCAGradientLayerAxial
.
I want something like below:
I have looked around for this issue and found that there is a way around this. But the explanations were not clear to me. So I want to know if I can draw radial gradients using CAGradientLayer
and if so, then how to do it?
From what I understood, you just need a layer that draws a gradient, and
CGContextDrawRadialGradient
works perfectly for that need. And to reiterate on what you said,CAGradientLayer
doesn't support radial gradients, and nothing we can do about that, except unnecessary swizzling that can be done cleanly with aCALayer
subclass.(note: the gradient drawing code was taken from here. It isn't what this answer is about.)
viewDidLoad
:CALayer
subclass: