我正在尝试绘制一个椭圆形挖空的320x480矩形.想象一下,在矩形上绘制一个填充的矩形,一个填充的椭圆,然后从矩形中移除椭圆,留下一个透明孔.
- (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);
}
Run Code Online (Sandbox Code Playgroud)
当我试图从矩形中移除椭圆时,它不起作用.
有人有解决方案吗?