Question

I have three points, A,B and C, the code to link the three points as following

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
    CGContextRef context = UIGraphicsGetCurrentContext();

    NSArray *points = @[       [NSValue valueWithCGPoint:CGPointMake(10.0f, 15.0f)],
                               [NSValue valueWithCGPoint:CGPointMake(100.0f, 170.0f)],
                               [NSValue valueWithCGPoint:CGPointMake(190.0f, 100.0f)],
                               ];

    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
    CGContextSetLineWidth(context, 2.0f);
    CGContextSetLineJoin(context, kCGLineJoinRound);
    CGContextSetLineCap(context, kCGLineCapRound);


    for(int i = 0;i<points.count; ++i){

        NSValue *pointValue = [points objectAtIndex:i];
        CGPoint point = [pointValue CGPointValue];
        if ( i == 0) {
            CGContextMoveToPoint(context, point.x, point.y);
        } else {
            CGContextAddLineToPoint(context, point.x, point.y);
        }
    }
    CGContextStrokePath(context);   
}

enter image description here

However, the junction of two lines is an angle, I need to join point B with a round corder. like following image:

enter image description here

how to do it?

Was it helpful?

Solution

What you have is 2 straight lines, what you're asking for is (possibly 2 straight lines, joined by) an arc / bezier curve.

Look at using CGPathAddArcToPoint or CGPathAddCurveToPoint or CGPathAddQuadCurveToPoint.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top