I am trying to draw a 320x480 rectangle that is hollowed by a ellipse. Imagine drawing a filled rectangle, over the rectangle an filled ellipse, and remove the ellipse from the rectangle, leaving a transparent hole.
- (void)drawRect:(CGRect)rect
{
// Drawing code.
CGContextRef context = UIGraphicsGetCurrentContext();
// Set color to red
CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
// Add rectange
CGContextAddRect(context, rect);
// Fill rectange
CGContextFillRect(context, rect);
// Create a elipse to be removed from rectange
CGPathRef circlePath = CGPathCreateMutable();
CGPathAddEllipseInRect(circlePath , NULL , elipseRect);
CGContextAddPath(context, circlePath);
CGContextSetRGBFillColor(context, 1.0, 1.0, 0.0, 1.0);
CGContextFillPath(context);
// clip elipse... (DO NOT WORK)
CGContextEOClip(context);
}
When I am trying to remove the elipse from the rectange, it does not work.
Anybody has a solution?