Drawing a curved custom shape
Following on from the Drawing a Custom Shape recipe, what if we want to define a shape that is made up not only of straight lines but also has a curved line? In this recipe, we will build a heart-shaped component using the arc and curve primitives of Path.
Getting ready
As usual, create a SwiftUI app called Heart.
How to do it…
We are going to follow the same steps that we implemented in the Drawing a custom shape recipe, adding curves and an arc from one point to another.Since the control points of a heart shape are in the midpoint of each side, we must add some convenient properties to the CGRect struct. CGRect is a structure inherited from the Core Graphics framework and has been present in iOS since the beginning. It is used to describe a rectangle in the drawing space. You define a rectangle with the coordinates of its origin and its two dimensions, width, and height. Let's get started with our custom shape. Perform the following steps...