使用Core Graphics绘制透明圆圈

时间:2013-10-14 08:12:56

标签: core-graphics

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

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);

1 个答案:

答案 0 :(得分:1)

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

相关问题