SwiftUI Lists & Forms Section

Section

Group rows in lists and inputs in forms using Section with optional headers and footers.


Example: Sections in List

Example

Demo.swift

ContentView.swift

App.swift

import SwiftUI

struct SectionListDemo: View {
  var body: some View {
List {
  Section(header: Text("Fruits"), footer: Text("End Fruits")) {
    Text("Apple"); Text("Banana")
  }
  Section(header: Text("Veggies")) { Text("Carrot") }
}
} }


Example: Sections in Form

Example

Demo.swift

ContentView.swift

App.swift

import SwiftUI

struct SectionFormDemo: View {
  @State private var name = ""
  @State private var notifications = true
  var body: some View {
Form {
  Section(header: Text("Profile"), footer: Text("Shown to others")) {
    TextField("Name", text: $name)
  }
  Section(header: Text("Preferences")) {
    Toggle("Notifications", isOn: $notifications)
  }
}
} }

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *