Question

I am trying to draw shape shown in figure. Background is white.. Hope it is visible to you..

enter image description here

I am using bezier path to draw this. I have provided bounds to shape as shown by blue border.

enter image description here

So far I am successfully able to draw just two lines(shown in green). I have to draw the one with red further.

enter image description here

I am unable to draw arc from this point. I can't understand how to pass correct parameters to addArcWithCenter.

Code

-(void) drawRect:(CGRect)rect
{
    //declare and instantiate the UIBezierPath object
    aPath = [UIBezierPath bezierPath];

    // Set the starting point of the shape.
    [aPath moveToPoint:CGPointMake(CGRectGetMinX(rect), CGRectGetMinY(rect))];

    // Draw some lines.
    [aPath addLineToPoint:CGPointMake(CGRectGetMaxX(rect), CGRectGetMinY(rect))];
    [aPath addLineToPoint:CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect) - 40)];
    [aPath addArcWithCenter:self.center radius:40 startAngle:3 *(M_PI / 2) endAngle:M_PI clockwise:NO];

    //set the line width
    aPath.lineWidth = 2;

    //set the stoke color
    [[UIColor greenColor] setStroke];

    //draw the path
    [aPath stroke];

}

I am new to core graphics. Please be lenient over me.. Thanks..

Was it helpful?

Solution

Try with this (as you can see, I've used addQuadCurveToPoint a variant of addCurveToPoint proposed by @wain - ask google for addCurveToPoint and switch to picture search to see how it work ) :

-(void) drawRect:(CGRect)rect
{
    UIBezierPath * aPath = [UIBezierPath bezierPath];

    // Set the starting point of the shape.
    [aPath moveToPoint:CGPointMake(CGRectGetMinX(rect), CGRectGetMinY(rect))];

    // Draw some lines.
    [aPath addLineToPoint:CGPointMake(CGRectGetMaxX(rect), CGRectGetMinY(rect))];



//changes start here !

    //the point look to be at 80% down
    [aPath addLineToPoint:CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect) * .8)];


    //1st arc
    //The end point look to be at 1/4 at left, bottom
    CGPoint p = CGPointMake(CGRectGetMaxX(rect) / 4, CGRectGetMaxY(rect));
    CGPoint cp = CGPointMake( (CGRectGetMaxX(rect) / 4) + ((CGRectGetMaxX(rect) - (CGRectGetMaxX(rect) / 4)) / 2) , CGRectGetMaxY(rect) * .8);

    [aPath addQuadCurveToPoint:p controlPoint:cp];


    //2nd arc
    //The end point look to be at 80% downt at left,
    CGPoint p2 = CGPointMake(CGRectGetMinX(rect), CGRectGetMaxY(rect) * .8);
    CGPoint cp2 = CGPointMake( (CGRectGetMaxX(rect) / 4) / 2 , CGRectGetMaxY(rect) * .8);

    [aPath addQuadCurveToPoint:p2 controlPoint:cp2];


    //close the path
    [aPath closePath];

    //set the line width
    aPath.lineWidth = 2;

    //set the stoke color
    [[UIColor greenColor] setStroke];

    //draw the path
    [aPath stroke];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top