1

I'm making a custom control and it was fine til my client says "I want it with gradients". So here I am. I need to draw an angle and fill it with gradient color. My previous code was this:

- (void)drawRect:(CGRect)rect{
CGContextBeginPath(context);
CGContextMoveToPoint(context, self.center.x, self.center.y);
CGContextAddArc(context, self.center.x, self.center.y, radius, radians(180), radians(minValue - 180), 0);
CGContextClosePath(context);
CGContextSetFillColorWithColor(context, gray);
CGContextFillPath(context);
}

With the CGContextAddArc() function I can draw my angle and paint it with CGContextSetFillColorWithColor() function, then close the path and voilá. But now I need to painted with gradients. I know that maybe I should use CGContextDrawRadialGradient, but don't know how to use it with an arc. I've been tried to figured out this with other question in StackOVerFlow and reading the doc, but I just can't get it.

FelipeDev.-
  • 3,113
  • 3
  • 22
  • 32
  • Have you read the [Gradients chapter of the Quartz 2D Programming Guide](http://developer.apple.com/library/ios/DOCUMENTATION/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_shadings/dq_shadings.html#//apple_ref/doc/uid/TP30001066-CH207-TPXREF101)? Did you have trouble understanding it? Do you need something other than a `CGGradient`? – rob mayoff Sep 13 '12 at 18:47
  • Also, if you need to fill a shape using a `CGGradient`, you need to clip the context to the shape. See [Clip the Context](http://developer.apple.com/library/ios/DOCUMENTATION/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_shadings/dq_shadings.html#//apple_ref/doc/uid/TP30001066-CH207-BBCBCJAE) in the Quartz 2D Programming Guide. – rob mayoff Sep 13 '12 at 18:48
  • @robmayoff Yes, I had read it. Specially the part of "Using a CGGradient Object", but as you said, am having problems understanding it. In fact I tried an answer of you (http://stackoverflow.com/questions/11783114/draw-outer-half-circle-with-gradient-using-core-graphics-in-ios) but I just can´t get it... – FelipeDev.- Sep 13 '12 at 19:03
  • Provide a 50 point bounty for the exact code and surely someone will do it. – David H Sep 13 '12 at 20:24

0 Answers0