2013-10-14 54 views
0

我想在屏幕上画一个透明的圆圈,屏幕上有一个0.5 alpha的黑色背景。但是我的透明圆圈没有清除黑色背景。我怎么能这样做?如果我想要一个透明的矩形,我可以使用CGContextClearRect(context,rect)并清除背景。任何想法的一个圆圈?用Core Graphics绘制一个透明圆圈

CGContextRef context = UIGraphicsGetCurrentContext(); 

// Fill the screen with black 0.5 alpha color 
CGContextSetRGBFillColor(context,0., 0., 0., 0.5); 
CGContextFillRect(context, CGRectMake(0.0, 0.0, 320, CGRectGetHeight(self.frame))); 

CGRect circleFrame = CGRectMake(0, 0, 320, 320); 

// Draw a circle with a transparent fill 
CGContextSetFillColor(context, CGColorGetComponents([UIColor clearColor].CGColor)); 
CGContextAddEllipseInRect(context, circleFrame); 
CGContextFillPath(context); 
+0

对于任何图纸请检查此链接https://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/BezierPaths/BezierPaths.html#//apple_ref/doc/uid/TP40010156-CH11- SW1 – virantporwal

回答

1

首先设置你的圈子的路径,然后拨打CGContextClip(),然后绘制你的背景。