Skip to content

Latest commit

 

History

History
114 lines (87 loc) · 2.32 KB

README.md

File metadata and controls

114 lines (87 loc) · 2.32 KB

Form

A container for grouping controls used for data entry, such as in settings or inspectors.

Create

    var body: some View {
        Form {
            Text("Hello, world!")
        }
    }

Multiple lines.

    var body: some View {
        Form {
            Text("Hello World")
            Text("Hello World")
            Text("Hello World")
        }
    }

You can show up to ten rows in a form. After that you will have to group. This is by design - parents can only support ten children.

Group

        Form {
            Group {
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
            }

            Group {
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
            }
        }

Groups don’t actually change the way your user interface looks, they just let us work around SwiftUI’s limitation of ten child views inside a parent – that’s text views inside a form, in this instance.

Section

Form {
    Section {
        Text("Hello World")
    }

    Section {
        Text("Hello World")
        Text("Hello World")
    }
}

Disable

Use .disabled() modifier.

struct ContentView: View {
    @State private var username = ""
    @State private var email = ""

    var body: some View {
        Form {
            Section {
                TextField("Username", text: $username)
                TextField("Email", text: $email)
            }

            Section {
                Button("Create account") {
                    print("Creating account…")
                }
            }
            .disabled(disableForm)
        }
    }
    
    var disableForm: Bool {
        username.count < 5 || email.count < 5
    }
}

Links that help