I've drawn two circles that overlap. I want to be able to fill and stroke them as a merged new shape.
At the moment, I create the path sequence once, stroke it, then create a copy of it, fill it and add the two identical paths on top of each other, so they appear as a single shape. Is there a better approach or is this ok?
Update: Here is a sample code:
CGMutablePathRef path = CGPathCreateMutable();
CGContextSetStrokeColorWithColor(theContext, strokeColor.CGColor);
CGContextSetLineWidth(theContext, 2);
CGContextSetFillColorWithColor(theContext, fillColor.CGColor);
CGRect rect1 = CGRectMake(0,0, mySize*0.6, mySize*0.6);
CGRect rect2 = CGRectMake(mySize*0.4,0, mySize*0.6, mySize*0.6);
CGPathAddEllipseInRect(path, NULL, rect1);
CGPathAddEllipseInRect(path, NULL, rect2);
CGContextAddPath(theContext, path);
CGContextDrawPath(theContext, kCGPathFillStroke);
CGPathRef pathFill = CGPathCreateCopy ( path );
CGContextAddPath(theContext, pathFill);
CGContextDrawPath(theContext, kCGPathFill);
CGPathRelease(path);
CGPathRelease(pathFill);
As you can see, I create a copy of the original path and draw it on top without the stroke, so in the end it looks like one united shape. Is there a way to avoid creating the duplicate?