如果你用 CGPoints 填充了“点”,这样的东西会起作用。警告:这是一项快速剪切、粘贴和编辑工作 - 因此可能会出现错误。另外,我将 stl::vector 用于“点”。您可能想要使用其他一些结构。
CGContextRef context = UIGraphicsGetCurrentContext();
CGMutablePathRef dataPath = CGPathCreateMutable();
bool firstPoint = YES;
for (int i=0; i < points.size(); ++i)
{
CGPoint point = points[i];
if (firstPoint)
{
CGPathMoveToPoint(dataPath, NULL, point.x, point.y);
firstPoint = NO;
}
else
{
CGPathAddLineToPoint(dataPath, NULL, point.x, point.y);
}
}
CGContextSetRGBStrokeColor( context, 1.0, 0.0, 0.0, 1.0);
CGContextSetLineWidth( context, 5);
CGContextBeginPath( context );
CGContextAddPath( context, dataPath );
CGContextDrawPath( context, kCGPathStroke);
CGPathRelease(dataPath);