I am creating a UIBezierPath
like this:
UIBezierPath *path = [UIBezierPath bezierPath];
[path addLineToPoint:CGPointMake(200.0, 40.0)];
[path addLineToPoint:CGPointMake(160, 140)];
[path addLineToPoint:CGPointMake(40.0, 140)];
[path addLineToPoint:CGPointMake(0.0, 40.0)];
[path closePath];
The problem is that when I try to draw my UIBezierPath
, it does not appear and I get an error:
<Error>: void CGPathCloseSubpath(CGMutablePathRef): no current point.
My drawing code is very basic:
UIGraphicsBeginImageContext(self.view.bounds.size);
[[UIColor whiteColor] set];
[myPath stroke];
UIGraphicsEndImageContext();
What am I doing wrong?
The error message is clear. One line of code was missing when I was creating my UIBezierPath
:
[path moveToPoint:CGPointMake(0, 0)];
I added it and everything worked like a charm.
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 0)];
[path addLineToPoint:CGPointMake(160, 140)];
[path addLineToPoint:CGPointMake(40.0, 140)];
[path addLineToPoint:CGPointMake(0.0, 40.0)];
[path closePath]
It is interesting that the error happened when I was trying to draw the line and not before - when I created it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With