如何在iPhone中绘制同心圆? [英] How to draw a concentric circle in iphone?

查看:196
本文介绍了如何在iPhone中绘制同心圆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想画个戒指。戒指应该填充在外圈。我提到了一份文件 http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_paths/dq_paths.html#//apple_ref/doc/uid/TP30001066-CH211-TPXREF101 。但仍然有问题得到结果。这是代码。

I want to draw a ring. Ring should filled in a outer circle. I referred a documentation http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_paths/dq_paths.html#//apple_ref/doc/uid/TP30001066-CH211-TPXREF101. But still had problem to get the outcome. Here is the code.

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


推荐答案

你需要更像这样的东西:

You need something more like this:

- (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填充路径时,它将基本上从外椭圆减去内椭圆。

This will add two ellipses to your current path (one being smaller than the other, but centered around the same point). EOFillPath will essentially "subtract" the inner ellipse from the outer ellipse when it fills the path.

要创建同心圆圈,如果这真的是你想要的,你可以简单地重复这个 - 更多 - 更小 - 椭圆。

To create "concentric" circles, if that's really what you wanted, you can simply repeat this for more - continually smaller - ellipses.

这篇关于如何在iPhone中绘制同心圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆