Using UIBezierPath with SwiftUI
In the preceding Drawing a custom shape and Drawing a curved custom shape recipes, we saw how to build a path using points relative to the container frame, but what if we have a figure built using absolute coordinates in UIBezierPath
, maybe from a previous UIKit project?
It turns out that we can translate UIBezierPath
into a Path
object, and then adapt it to the contained frame, scaling it to fill it.
Getting ready
For this recipe, we are going to use a pretty long UIBezierPath
definition of an ace of spades shape, so I won't add the full description here, but you can find it in the repo at SwiftUI-Cookbook/Chapter06 - Drawing with SwiftUI/05 - Using UIBezierPath with SwiftUI/AceOfSpadeApp/AceOfSpadeApp/AceOfSpade+UIBezierPath.swift.
Let's create a project called AceOfSpadeApp
and add that file to it.
How to do it...
This recipe is really straightforward; the only thing to take note of is to calculate the scale factor in...