At the moment, I'm trying to work out how to animate a custom button which I have an image of and have the coordinates of but I've found that you can create a button/object both by using the CGPath class or the UIBezierPath class. Can somebody please tell me what the difference between the two are?
2 Answers
CGPath is an opaque type from the CoreGraphics library, while UIBezierPath is an Obj-C class in UIKit. UIBezierPath is a wrapper around CGPath (you can convert between them easily), with a more object-oriented interface and a few convenience methods. Using CGPath may be marginally faster as it doesn't have to go through Obj-C (although who knows how it works with Swift) and it has more advanced functions like CGPathApply. Importantly, UIBezierPath conforms to NSCoding, meaning you get serialization/deserialization for free.
tl;dr: use UIBezierPath unless you have some reason not to.

- 115,675
- 35
- 233
- 266
-
thanks for the information it was actually very helpful! As you can probably see, I'm basically an absolute beginner. However, what I was trying to get at is that I was trying to create a path for a button, which I have but only in pictures. It simply consists of a green circular progress bar which I believe is called a transition from one state to another like in the website below. The original website I have been looking for guidance is the following: http://robb.is/working-on/a-hamburger-button-transition/ but I need help as to how to fully implement this into my project with my button. – BrianCO Aug 23 '14 at 17:59
-
This post here gives a nice explanation why this answer is incorrect. http://stackoverflow.com/questions/6327817/why-is-uibezierpath-faster-than-core-graphics-path – khunshan Feb 03 '16 at 13:11
-
4`UIBezierPath` has a coordinate system different from `CGPath`: in `CGPath` (Quartz 2D) [the origin is at the bottom-left](https://developer.apple.com/library/mac/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_overview/dq_overview.html#//apple_ref/doc/uid/TP30001066-CH202-CJBBAEEC) while in `UIBezierPath` (UIKit) [the origin is at the top-left](https://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/BezierPaths/BezierPaths.html#//apple_ref/doc/uid/TP40010156-CH11-SW5). This bit me once. – Franklin Yu Apr 26 '16 at 20:46
-
tl;dr goes on top ;) – Alex Aug 25 '16 at 02:51
To expand a bit on what jtbandes wrote, there's another distinction: CGPath
is just a mathematical description of a shape. It has no drawing-specific properties or capabilities. Instead, drawing properties are part of the CGContext
as is the actual drawing operation. You set things like color, line width, etc. on the context before the drawing operation, but those are not part of the path itself.
By contrast, UIBezierPath
has drawing properties and drawing operations.

- 88,520
- 7
- 116
- 154
-
I'm not sure exactly what you mean. CGPaths are drawn with [CGContextStrokePath](https://developer.apple.com/library/ios/documentation/graphicsimaging/reference/CGContext/Reference/reference.html#//apple_ref/c/func/CGContextStrokePath) and other such functions. – jtbandes Aug 28 '14 at 16:33
-
1That's a function on a `CGContext`. My main point, because it has confused people in the past, is that a `CGPath` doesn't have, for example, a line thickness or a line dash pattern. – Ken Thomases Aug 28 '14 at 18:36