MultiPicker helps you create Pickers which allow multiple selection in your SwiftUI
apps.
https://github.com/anikaseibezeder/MultiPicker.git
- Add a
Set
, which will later on hold the selected values.
@State private var selection = Set<String>()
- Add the
MultiPicker
to your view by providing atitle
, theselection
Set, an array containing the availableoptions
and what you want to use as the label of those options.
private let options = ["Option 1", "Option 2"]
MultiPicker("Options",
selection: $selection,
options: options) { $0 }
Displays the options similar to the default
SwiftUI Picker
.
allowsMultipleSelection
- define if the Picker should allow multiple selection
.multiPickerStyle(DefaultMultiPickerStyle(allowsMultipleSelection: true))
Displays the options in a grid.
columns
- define how many columns should be used to display the optionsallowsMultipleSelection
- define if the Picker should allow multiple selection
.multiPickerStyle(GridPickerStyle(columns: 5,
allowsMultipleSelection: true))
For more information on how to use MultiPicker, see the attached Demo
project.
Just open it and run the app.
Some parts of this package are based on this blog post by Jeehut.
Thanks for providing a really simple explanation on how to create a Multi Selector in SwiftUI
.
MultiPicker is available under the MIT license. See the LICENSE file for more information.