How to draw a concentric circle in iphone?

后端 未结 1 1966
太阳男子
太阳男子 2021-02-06 07:15

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/drawing

1条回答
  •  伪装坚强ぢ
    2021-02-06 07:31

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

    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.

    0 讨论(0)
提交回复
热议问题