Drawing Hollow circle in iPhone

RVN picture RVN · May 2, 2011 · Viewed 10.1k times · Source

i need to draw the following image enter image description here

The Gray part is what i want to draw over another image what is the Code i need to use using CGContext methods, i tried using the CGContextAddArc but failed because when i fill the stroke the center hollow is also filled with the grey texture.

Any help appreciated.

Info : I have the Complete Blue Image , i need to add the Semi Circle above the blue image

Thanks

Answer

Ole Begemann picture Ole Begemann · May 2, 2011

Have a look at Filling a Path in the Core Graphics documentation. Basically, what you do is add two arcs to your path (the outer and the inner one) and then use Core Graphics fill rules to your advantage. The code would look something like this:

CGMutablePathRef path = CGPathCreateMutable();

// Add the outer arc to the path (as if you wanted to fill the entire circle)
CGPathMoveToPoint(path, ...);
CGPathAddArc(path, ...);
CGPathCloseSubpath(path);

// Add the inner arc to the path (later used to substract the inner area)
CGPathMoveToPoint(path, ...);
CGPathAddArc(path, ...);
CGPathCloseSubpath(path);

// Add the path to the context
CGContextAddPath(context, path);

// Fill the path using the even-odd fill rule
CGContextEOFillPath(context);

CGPathRelease(path);