Picker is a control in SwiftUI which allows you to select a value from a list of possible options. There are many types of inbuilt pickers coming in SwiftUI and it’s really easy to implement.
Automatic Style Picker (In Form)
Automatic style of picker in form will come with navigation link setup.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import SwiftUI struct ContentView: View { var options = ["One", "Two", "Three"] @State private var selectedOption = "One" var body: some View { NavigationView { Form { Picker("Select", selection: $selectedOption) { ForEach(options, id: \.self) { Text($0) } }.pickerStyle(.automatic) } .navigationTitle("Testing the form!") } } } |
Inline Style Picker
.pickerStyle(.inline) this will look as follows:
Menu Style Picker
.pickerStyle(.menu) this will look as follows:
Segmented Style Picker
.pickerStyle(.segmented) this will look as follows:
Wheel Style Picker
.pickerStyle(.wheel) this will look as follows:
Conclusion
Let me know if you have any questions, comments, or feedback – either via Twitter or email.
Happy Coding 🙂