views:

64

answers:

2

For an iPhone application I want to draw a circle, that is only for an x percentage filled.

Something like this:

alt text

I have no problems calculating the radius, the degrees or the radians, that is no problem. Also drawing the circle is already done. But how do I get the iPhone SDK to draw the part that is filled.

I can draw a rectangle that size, but not part of a circle.

I just want to draw that on a a normal context.

Hope someone can give me any pointers here.

+3  A: 

Use the arc methods:

CGContextAddArc(context,
                centerX,
                centerY,
                radius,
                startAngleRadians,
                endAngleRadians,
                clockwise ? 1 : 0);     

See the documentation for CGContextAddArc. (Aside: Does anyone know how to link directly to the docs for a function, given Apple's annoying javascript-laden documentation?)

David M.
Find the link on the left pane and copy its address - [CGContextAddArc (absolute)](http://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html#//apple_ref/doc/uid/TP30000950-CH1g-F17001)
jrtc27
A: 

Try this:

CGContextMoveToPoint(the center point)
CGContextAddLineToPoint(the starting point of the fill path on the circumference)
CGContextAddArcToPoint(the ending point of the fill path on the circumference)
CGContextAddLineToPoint(the center point)
CGContextFillPath
mharper