Home > AI > IOS > SwiftUI >

(View)Form

Example 1

struct TestForm: View {
  @State var good:String
    var body: some View {
      NavigationView {
        Form {
          TextField("Good", text: $good)
        }.navigationTitle("Title")
      }
    }
}

Example 2: with Toggle and Picker

struct TestForm: View {
  @State var listeningTimeReminderVar: Bool = true
  @State var readingTimeReminderVar: Bool = true
  @State var speedModeVar: Bool = false
  @State var previewIndex: Int = 1
  
  
  
    var body: some View {
      NavigationView {
        Form {
          Section(header: Text("Personal Setting")) {
            Text("personal avator")
            Text("phone")
          }
          
          
          
          Section(header: Text("Study Setting")) {
            Toggle("ListeningTimeReminder", isOn: $listeningTimeReminderVar)
            Toggle("ReadingTimeReminder", isOn: $readingTimeReminderVar)
            Toggle("speedMode", isOn: $speedModeVar)
            
          
            Picker(selection: $previewIndex, label: Text("Show Previews")) {
              ForEach(0 ..< 3) {_ in
                        Text("good")
                    }
                }
          }
          
          Section(header: Text("Other Services")) {
            HStack{
              Text("Version update")
              Spacer()
              Text("v7.1.7")
            }
          }
          
          
        }.navigationBarTitle("Setting Center", displayMode: .inline)
      }
    }
}

Leave a Reply