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 and 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
Let's start by creating a new SwiftUI project called ButtonsApp
.
How to do it…
Let's create a home screen with buttons for each of the items we want to go over. Once clicked, we'll use SwiftUI's navigation view to go to the view that implements the clicked concept. The steps are given here:
- Add a new SwiftUI view file called
ButtonView
to the project: File | New | File (or press the shortcut keys + N). - Select SwiftUI View from the UI templates.
- In the Save As field of the pop-up menu, enter the filename
ButtonView
. - Repeat Step...