开发者

Smooth arcs in quartz?

While developing a rounded rectangle widget I encountered the follow开发者_Python百科ing problem: path built with arcs looks ugly when stroked.

picture http://img51.yfrog.com/img51/8919/quartzarc.png

How to make the stroked arcs look nicer?


One trick with quartz drawing is to offset things by half a pixel. Try insetting your rect before drawing:

rect = CGRectInset( rect , -0.5 , -0.5 );

Doing +0.5 instead of -0.5 would make the rectangle smaller.


Here's outline of the solution valid for any given line width:

- (void)drawRect:(CGRect)rect {
    CGFloat lineWidth=1.5;
    rect = CGRectInset(rect, lineWidth , lineWidth);
    ...
    CGContextSetLineWidth(context, lineWidth);
        ...
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜