Say I have a CGPath which is a circle in the CGContextRef. What I would like to do is to fill the inverse of the path with color. Demonstrated below where the circle is the current path drawn and I would like to fill the inverse of the circle with color, leaving a hollow hole:

First add the rectangle to the path and then add the circle (or whatever your path is) to the same path. Then do an even-odd fill which will won't fill the circle because that is covered by both the circle and the rectangle.
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, bigRect); // add the big rect
CGPathAddPath(path, NULL, circlePath); // add your shape (the circle)
CGContextDrawPath(path, kCGPathEOFill); // even-odd fill
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With