您的位置:首页 > 其它

CGContext /NSBezierPath stroke line width thicker

2014-09-24 10:32 253 查看
down
votefavorite

rounded corners are clearly thicker than the rest of the path.

当我们用整数定义某路径时,路径的坐标总是在两个像素之间的,而NSBezierPath在绘制线条时,线条宽度刚好平均分配在路径两侧,而当宽度为1或其它奇数时,两侧就会出现半像素的情况,并且在非Retina显示下,每一个需要绘制的像素是与屏幕最终显示的单元是一一对应的,如图:




CGContextRef context = UIGraphicsGetCurrentContext();
CGContextBeginPath(context);

//
NSInsetRect
(rect, lineWidth/2, lineWidth/2)

NSRect myProperBounds = NSInsetRect(
rect
, 1.0, 1.0);[/code]
CGContextMoveToPoint(context, rect.origin.x + kRoundedRectButtonRadius, rect.origin.y);
CGContextAddArc(context, rect.origin.x + rect.size.width - kRoundedRectButtonRadius, rect.origin.y + kRoundedRectButtonRadius, kRoundedRectButtonRadius, 3 * M_PI_2, 0, NO);
CGContextAddArc(context, rect.origin.x + rect.size.width - kRoundedRectButtonRadius, rect.origin.y + rect.size.height - kRoundedRectButtonRadius, kRoundedRectButtonRadius, 0, M_PI_2, NO);
CGContextAddArc(context, rect.origin.x + kRoundedRectButtonRadius, rect.origin.y + rect.size.height - kRoundedRectButtonRadius, kRoundedRectButtonRadius, M_PI_2, M_PI, NO);
CGContextAddArc(context, rect.origin.x + kRoundedRectButtonRadius, rect.origin.y + kRoundedRectButtonRadius, kRoundedRectButtonRadius, M_PI, 3 * M_PI_2, NO);

CGContextClosePath(context);
CGContextSetLineWidth(context, 1.7);
CGContextStrokePath(context);


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  line thicker