用CGContextAddCurveToPoint替换CGContextAddLineToPoint

时间:2014-02-21 11:21:48

标签: ios cgcontext quartz-2d curve

我有一个CGPoint值数组。现在我正在做这样的事情:

for(int i=1; i<coveringValuesArray.count; ++i){
    CGPoint nextPoint = [coveringValuesArray objectAtIndex:i];
    nextPoint = [self offsetPoint:nextPoint on:rect.origin];
    CGContextAddLineToPoint(ctx, nextPoint.x, nextPoint.y);
}

需要用曲线绘制此图表。

1 个答案:

答案 0 :(得分:0)

试试这个

 for(int i=1; i<coveringValuesArray.count; ++i){
        CGPoint nextPoint = [coveringValuesArray objectAtIndex:i];
        nextPoint = [self offsetPoint:nextPoint on:rect.origin];
        CGContextFillRect(context, CGRectMake(nextPoint.x,nextPoint.y,1,1));
    }

或者可以使用贝塞尔曲线

UIBezierPath* path = [UIBezierPath bezierPath];
CGPoint firstPoint = coveringValuesArray[0];
[path moveToPoint:firstPoint];
for(int i=1; i<coveringValuesArray.count; ++i){
        CGPoint nextPoint = [coveringValuesArray objectAtIndex:i];
        nextPoint = [self offsetPoint:nextPoint on:rect.origin];
        [path addLineToPoint:nextPoint];
 }
[path closePath];