开发者

Fill a circle with an outline

I need to draw a filled circle, and it needs to have an outline that is a dif开发者_C百科ferent colour. Right now I'm doing this by creating two circles, and filling one then stroking the other.

CGContextFillEllipseInRect(context, CGRectMake(10, 10, 80, 80));
CGContextStrokeEllipseInRect(context, CGRectMake(10, 10, 80, 80));

The problem is that the circle looks a little offset and uneven. Is there a function that allows the simultaneous drawing of a circle with an outline in a single line?


The problem is that the circle looks a little offset and uneven.

What do you mean by that? Please edit your question to include a screenshot.

Did you turn off anti-aliasing? If so, that may be the cause.

Did you create the context yourself? If so, please edit your question to include the code that does that.

Is there a function that allows the simultaneous drawing of a circle with an outline in a single line?

You can use CGContextAddEllipseInRect to append the ellipse to the context's current path, then use CGContextDrawPath with the kCGPathFillStroke operation. It should be slightly faster (since the path is only created once), but shouldn't make any other difference, though.


Try adding some thickness to the outline by stroking with a larger pen line width. You may also need to inset the rectangle of by half the width of the pen.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜