0

我已经知道如何在两点之间画一条线,但这条线似乎不是那么平滑。我该怎么做才能使它更顺畅?谢谢。

- (void)drawLineFrom:(CGPoint)start To:(CGPoint)end {
// begin image context
UIGraphicsBeginImageContext(self.imageLineView.frame.size);

// define image rect for drawing
[self.imageLineView.image drawInRect:CGRectMake(0, 0, imageLineView.frame.size.width, imageLineView.frame.size.height)];

// set line properties
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 2.0f);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0f, .0f, .0f, 1.0);

// move context to start point
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), start.x, start.y);

// define path to end point
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), end.x, end.y);

// stroke path
CGContextStrokePath(UIGraphicsGetCurrentContext());

// flush context to be sure all drawing operations were processed
CGContextFlush(UIGraphicsGetCurrentContext());

// get UIImage from context and pass it to our image view
imageLineView.image = UIGraphicsGetImageFromCurrentImageContext();

// end image context
UIGraphicsEndImageContext();
}

在此处输入图像描述

4

2 回答 2

3

您可以使用贝塞尔路径绘制平滑线。

你可以在这里获得更多信息。 贝塞尔路径

于 2013-06-03T08:44:45.760 回答
0

尝试启用抗锯齿。您需要在 Info.plist 中将 UIViewEdgeAntialiasing 键设置为 YES。

于 2013-06-03T08:52:39.960 回答