Search code examples
ioscore-graphicsquartz-2duibezierpath

What is the difference between CGContextAddLineToPoint and addLineToPoint function in UIBezierPath?


I have rendered some basic shapes using quartz-2d. I came across two methods to draw a line. First is to get a context using UIGraphicsGetCurrentContext() and then draw the line using CGContextAddLineToPoint.

And other way is to define a UIBezierPath object and draw using its function addLineToPoint

[bezierPath addLineToPoint:CGPointMake(10, 10)];

And then I have to add bezierPath to the context using CGContextAddPath.

So I wanted to know the difference between these two approaches as both are used to draw only a line. Is there a performance issue between these two? Also which method is better under what circumstances.


Solution

  • The UIBezierPath is an object from the UIKit, and allow you to use a set of function mixing particular curve with control point but also with a normal line.

    Being an object from the UIKit you are not able to use CGContextAddLineToPoint, but anyway at the end you need to add the path in the context with CGContextAddPath.

    With CGContexAddLineToPoint instead you draw directly on the context.

    So my suggest is to use this last way if you have not particular reasons (like amazing curve with different control point). Otherwise, use UIBezierPath.