SwiftUI - Form

Many a times we need to design a User Interface where we need to take users inputs in TextFields, Date Pickers, Pickers, Toggles. As of now what we followed is we either used a ScrollView for a fixed set of inputs or TableView for list of inputs. SwiftUI provides us with a simple solution called Form for this.
Form is a container or a collection of user input controls. Forms can contain Sections which can group input controls. Also keep that in mind that forms are scrollable, we don't need to worry about what will happen if we add multiple items and it gets out of the screen.

Lets see following example:

struct ContentView: View {
    @State private var name = ""
    @State private var age = ""
    var body: some View {
        Form {
            Text("Personal Details Form")
                .font(.headline)
                .foregroundColor(.red)
            TextField("Name", text: $name)
            TextField("Age", text: $age)
        }
    }
}

This is an input form with a label and two textfields.
Avoid variables name and age for now I will explain it in my next Post.

Output is like this:




Comments

Popular posts from this blog

UITableView - Add or Remove Rows Dynamically (Objective C & Swift Source codes)

payUmoney Payment Gateway Integration in iOS App (Objective C)

Check Internet Connectivity Using AFNetworking 2.0