toastersocks / MultiPicker

A Picker for iOS that can be used to choose from one, one or none, or multiple options.
MIT License
30 stars 6 forks source link
multipicker picker swift swiftui

MultiPicker


A picker for selecting from multiple options. Or no options

SwiftUI's Picker on iOS only allows choosing exactly one option. If you need a picker that allows selecting one optional value, or multiple values from a set, you're outta luck. MultiPicker can do all three!

Navigation link style, plain text choice style, light mode, English Navigation link style, rich choice style, dark mode, English Navigation link style, rich choice style, dark mode, Portuguese Navigation link style, rich choice style, dark mode, Arabic Inline style, leading and trailing selection indicator, light mode, English Inline style, leading and trailing selection indicator, dark mode, Arabic

MultiPicker tries to make its API as close to the SwiftUI Picker's as possible.

MultiPicker supports localization and accessibility and has better default accessibility than Picker. MultiPicker supports string initializers as well as custom label views. MultiPicker has a few additions and deviations from Picker:

Usage

Usage of MultiPicker is very similar to Picker:

struct MyView: View {
    @State private var selection: Set<Model> = []
    @State private var options: [Model]

    var body: some View {
        Form {
            MultiPicker("Choose something", selection: $selection) {
                ForEach(options) { option in
                    ModelCell(model: option)
                        .mpTag(option)
                }
            }
            .mpPickerStyle(.navigationLink)
        }
    }
}

Check the documentation for more in-depth usage.

Installing

Swift Package Manager

Via Xcode