How does one set up, modify, and clear a clipping rectangle inside a iOS drawRect for clipping generic CG drawing of lines, text, images, etc. to a small portion of a view?
Is it possible to use a more complex clipping region that is a composite of a bunch of rectangles and circles?
You can set a clipping area with arbitrary paths, not restricted to rectangles. The followings are some ways of doing it:
You can draw an arbitrary path and set a clipping area with it. For example:
CGContextBeginPath(context);
//draw a path here
CGContextClosePath(context);
CGContextClip(context);
//following drawing on the context will be clipped
If you want to use a mask image to set a clipping area, use CGContextClipToMask method.
See Apple's 'QuartzDemo' sample project for more usages.