在iOS中使用核心绘图上下文(Core Graphics Context)绘制圆形 - 使用Objective-C或Swift

3

我是这样画圆的:

CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(contextRef, 2.0);
//CGContextSetRGBFillColor(contextRef, 0, 0, 1.0, 1.0);
//CGContextSetRGBStrokeColor(contextRef, 0, 0, 1.0, 1.0);
 CGContextSetStrokeColorWithColor(contextRef, [color CGColor]);
CGRect circlePoint = (CGRectMake(coordsFinal.x, coordsFinal.y, 50.0, 50.0));

CGContextFillEllipseInRect(contextRef, circlePoint);

我想知道如何让圆形内部为空,以便我可以看到它后面的内容。

2个回答

9

您的意思是只需要轮廓?这种情况下,请使用CGContextStrokeEllipseInRect

CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(contextRef, 2.0);
CGContextSetStrokeColorWithColor(contextRef, [color CGColor]);
CGRect circlePoint = (CGRectMake(coordsFinal.x, coordsFinal.y, 50.0, 50.0));

CGContextStrokeEllipseInRect(contextRef, circlePoint);

2

Swift 3

let currentContext = UIGraphicsGetCurrentContext()
currentContext?.setLineWidth(2.0)
currentContext?.setFillColor(color.CGColor)
let circleRect = CGRect(x: coordsFinal.x, y: coordsFinal.y, width: 50.0, height: 50.0)

currentContext?.strokeEllipse(in: circleRect)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接