daredevil1234
daredevil1234

Reputation: 1425

CGPath vs UIBezierPath

Working with a piece of code that gets a CGPath in the following way:

let dirX = -spread
let rect = bounds.insetBy(dx: dirX, dy: dirX)
let cgPath = UIBezierPath(rect: rect).cgPath

Is there a way I can just use that rect directly to get the CGPath?

I know there is

CGPath(rect: CGRect, transform: UnsafePointer<CGAffineTransform>)

But I am not sure if it is simple to get the same CGPath directly with the init, because I am not sure how to use the UnsafePointer.

Explanations and Examples welcome.

Upvotes: 2

Views: 461

Answers (1)

Reinier Melian
Reinier Melian

Reputation: 20804

You can use CGPath(rect: CGRect, transform: UnsafePointer<CGAffineTransform>?) and pass nil in CGAffineTransform as is optional

let dirX = -spread
let rect = bounds.insetBy(dx: dirX, dy: dirX)
let cgPath = CGPath(rect: rect, transform: nil)

But this will not have any impact in your app functioning, even in the amount of code because anyway is one line

Upvotes: 1

Related Questions