2

I want to draw ellipse gradient in Swift.

In CSS:

background: radial-gradient(50% 25% at 20% 30%, #ffffff, #ff0000);

I expect appearance to be like following:

enter image description here

I know I can draw circle gradient by using CGContext.drawRadialGradient(_:startCenter:startRadius:endCenter:endRadius:options). But, I don't know how to draw ellipse gradient.

Any idea? Thanks in advance.

Yuki.M
  • 415
  • 5
  • 15
  • Check if this is helpful to you: https://stackoverflow.com/a/31854064/12830762 you need to change the code according to your need – Niraj Mar 18 '20 at 06:28
  • @Niraj Thank you for your quick comment. But, the post you mentioned is not about ellipse gradient but about radial gradient. I want to know the way to draw ellipse gradient. – Yuki.M Mar 18 '20 at 07:05
  • 1
    @Niraj I came across your answer while trying to figure this out, I just wanted to comment in case anyone else comes across this, create an ellipse CAShapeLayer and apply that ellipse shape layer as a mask to a CAGradientLayer of type .radial. It will scale properly to create an elliptical gradient, pretty neat! – Eliot S Winchell Jan 13 '21 at 06:15

0 Answers0