Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between CGPath and UIBezierPath()? [closed]

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?

like image 878
BrianCO Avatar asked Aug 23 '14 01:08

BrianCO


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.

like image 59
jtbandes Avatar answered Oct 13 '22 20:10

jtbandes


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.

like image 11
Ken Thomases Avatar answered Oct 13 '22 21:10

Ken Thomases