gpt4 book ai didi

iphone - 如何在iphone中画一个同心圆?

转载 作者:太空狗 更新时间:2023-10-30 03:31:45 26 4
gpt4 key购买 nike

我想画一个圆环。环应填充在外圈中。我引用了文档 http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_paths/dq_paths.html#//apple_ref/doc/uid/TP30001066-CH211-TPXREF101 .但仍然无法获得结果。这是代码。

CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, rect);
CGContextSetRGBFillColor(ctx, 0.0, 255.0, 1.0, 1.0);CGContextFillPath(ctx);
CGContextStrokeEllipseInRect(ctx, CGRectMake(125, 125, 150, 150));
CGContextBeginPath(ctx);
CGContextEOFillPath(ctx);
CGContextFillEllipseInRect(ctx, CGRectMake(100, 100, 200, 200));

最佳答案

你需要更多这样的东西:

- (void)drawRect:(CGRect)rect
{
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);
}

这将向您当前的路径添加两个椭圆(一个比另一个小,但以同一点为中心)。 EOFillPath 在填充路径时实质上会从外部椭圆中“减去”内部椭圆。

要创建“同心”圆,如果这确实是您想要的,您可以简单地重复此操作以获得更多(不断变小)的椭圆。

关于iphone - 如何在iphone中画一个同心圆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6061200/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com