我正在尝试绘制一个由椭圆形中空的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);
}
当我尝试从矩形中去除椭圆时,它没有起作用。有人有解决方案吗?