我被困在这个问题上了。我需要在前一个终点和下一个起点之间画一条线。我在两点之间画一条线的代码是
- (void)drawRect:(CGRect)rect
{
CGContextRef c=UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, 4.0);
CGFloat red[4]={0.0f, 0.0f, 0.0f, 1.0f};
CGContextSetStrokeColor(c, red);
CGContextBeginPath(c);
CGContextMoveToPoint(c, 50.0f, 50.0f);
CGContextAddLineToPoint(c, 100.0f, 100.0f);
CGContextStrokePath(c) ;
}
我如何给出多个点,以便我可以将其显示为图表。 提前致谢
最佳答案
附带说明一下,Apple 更喜欢您使用高级 UIKit 方法而不是 Core Graphics 调用来绘制直线和曲线等简单的东西,因此您可以像这样重写您的方法:
[[UIColor redColor] setStroke];
UIBezierPath *linePath = [UIBezierPath bezierPath];
[linePath moveToPoint:CGPointMake(50.0, 50.0)];
[linePath addLineToPoint:CGPointMake(100.0, 100.0)];
[linePath setLineWidth:4.0];
[linePath stroke];
关于iphone - 在上一个终点和下一个起点之间画一条线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12578729/