我正在尝试实现一个形状为
这是我正在尝试的当前代码。它实现了同心圆,但外部圆被填充。帮帮我。
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextAddEllipseInRect(ctx, rect);
CGContextAddEllipseInRect(ctx,
CGRectMake(
rect.origin.x + 10,
rect.origin.y + 10,
rect.size.width - 20,
rect.size.height - 20));
CGContextSetFillColor(ctx, CGColorGetComponents([[UIColor blueColor] CGColor]));
CGContextEOFillPath(ctx);
最佳答案
制作两个上下文并仅填充内部圆
- (void)drawRect:(CGRect)rect
{
CGContextRef outer = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(outer, 1.5);
CGContextSetStrokeColorWithColor(outer, [UIColor blueColor].CGColor);
CGContextAddEllipseInRect(outer, CGRectMake(rect.origin.x + 5, rect.origin.y + 5, rect.size.width - 10, rect.size.height - 10));
CGContextStrokePath(outer);
CGContextRef inner = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(inner, 1.5);
CGContextSetFillColorWithColor(inner, [UIColor blueColor].CGColor);
CGContextAddEllipseInRect(inner, CGRectMake(rect.origin.x + 15, rect.origin.y + 15, rect.size.width - 30, rect.size.height - 30));
CGContextFillPath(inner);
}
我在外部上下文中添加了5个单位的填充,以使其看起来像圆形而不是圆角矩形。
关于ios - 绘制同心圆:应填充内圆,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22829494/