Adding buttons and navigating with them
In this recipe, we will learn how to use various buttons available in SwiftUI. We will use a Button
view to trigger the change of a count when clicked, implement a navigationView
to move between various SwiftUI views, and an EditButton
to remove items from a list. We will also briefly discuss the MenuButton
and PasteButton
, only available in macOS.
Getting ready
Create a new SwiftUI project named ButtonsApp
.
How to do it…
- Add a new SwiftUI
View
file calledButtonView
to the project: File | New | File, or press the shortcut keys: ⌘ + N. - Select SwiftUI View from the User Interface templates.
- In the Save As field of the pop-up menu, enter the filename
ButtonView
. - Repeat step 1 and enter the filename
EditButtonView
. - Repeat step 1 and enter the filename
PasteButtonView
. - Repeat step 1 and enter the filename
MenuButtonView
. - Open the
ContentView.swift
file and create aNavigationView
to navigate...