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);
...
}
精彩评论