Showing and hiding sections in forms
Forms provide a means of getting information from the user. Long forms can, however, discourage users from providing information. Users not completing a form may mean fewer people signing up for your app or providing payment information.
In this recipe, we will learn how to show/hide an additional address section of a form based on user input.
Getting ready
Create a SwiftUI Project named SignUp
.
How to do it…
We will create a signup form with sections for various user input. The additional address sections will be shown or hidden based on how long the user has lived at their current address. Use the following steps:
- Create a new SwiftUI View called
signUpView
:a. Press ⌘ + N.
b. Select SwiftUI View.
c. Click Next.
d. Click on the Save As field and enter the text
signUpView
.e. Click Finish.
- Declare and initialize the
@State
variables that will be used in the form:@State private var fname = "" @State...