How can we avoid the extra bezier curve line?

55 views Asked by At

Can we avoid the extra bezier curve line after the last point in Bezier graph? Is there any property for that?

Please check the screenshot

We need just end-end curve graph, no extra curve. Please share the solutions/suggestion. Update: Please check the code below,

- (void)drawRect:(CGRect)rect {
UIBezierPath *line = [UIBezierPath bezierPath];
NSValue *value = points[0];
CGPoint p1 = [value CGPointValue];
[line moveToPoint:p1];if (points.count == 2) {
    value = points[1];
    CGPoint p2 = [value CGPointValue];
    [line addLineToPoint:p2];
    return line;
}

for (NSUInteger i = 1; i < points.count; i++) {
    value = points[i];
    CGPoint p2 = [value CGPointValue];

    CGPoint midPoint = midPointForPoints(p1, p2);
    [line addQuadCurveToPoint:midPoint controlPoint:controlPointForPoints(midPoint, p1)];
    [line addQuadCurveToPoint:p2 controlPoint:controlPointForPoints(midPoint, p2)];

    p1 = p2;
}
 CAShapeLayer *pathLayer = [CAShapeLayer layer];
    pathLayer.frame = self.bounds;
    pathLayer.path = line.CGPath;
    pathLayer.strokeColor = self.color.CGColor;
    pathLayer.fillColor = nil;
    pathLayer.opacity = self.lineAlpha;
    pathLayer.lineWidth = self.lineWidth;
    pathLayer.lineJoin = kCALineJoinBevel;
    pathLayer.lineCap = kCALineCapRound;
 [self.layer addSublayer:pathLayer];}


static CGPoint midPointForPoints(CGPoint p1, CGPoint p2) {
return CGPointMake((p1.x + p2.x) / 2, (p1.y + p2.y) / 2);} 

Thanks!

0

There are 0 answers