2

I'm a beginning programmer in Swift, and I'm attempting to draw an ellipse in swift with a rainbow gradient that fills it, similar to a color wheel.

I'm confused as to how to approach this. I'm currently drawing the ellipse:

    let context: CGContext = UIGraphicsGetCurrentContext()!
    context.setFillColor()
    context.addEllipse(in: Rectangle)
    context.drawPath(using: .fill)

But instead of setting the fill color, I want to draw a rainbow gradient inside it.

I've looked at this gradient method:

context.drawLinearGradient()

But I'm not sure how to go about it. If someone could point me in the right direction, I'd appreciate it. Thanks!

codex
  • 273
  • 2
  • 17
  • 1
    CGContext does not have built-in support for angular gradients. Some third-party libraries are available for this, for instance: https://github.com/paiv/AngleGradientLayer – jtbandes Feb 01 '17 at 04:25
  • 1
    See also: http://stackoverflow.com/questions/6485468/drawing-an-angle-angular-conical-arcing-gradient-in-objective-c-ios-using – jtbandes Feb 01 '17 at 04:27

0 Answers0