Using SwiftUI's built-in shapes
SwiftUI contains a few basic shapes such as rectangles, circles, and so on that can be used to create more complex shapes by combining them.
In this recipe, we'll explore how to create them, add a border and a fill, and how to lay out the shapes.
There will be more than we can show here, but with this recipe as a starting point, you can modify the shapes to discover all the potential of the built-in shapes of SwiftUI.
Getting ready
As usual, let's start by creating a new SwiftUI project with Xcode, calling it BuiltInShapesApp.
How to do it...
SwiftUI has five different basic shapes:
RectangleRoundedRectangleCapsuleCircleEllipse
In the ContentView body, we add a vertical stack to contain all of them:
- Create a
VStackcomponent with a spacing of10and horizontal padding of20:var body: some View { VStack(spacing: 10) { } ...