How it works
InlinePickerStyle is a picker style that lays a picker's choices out directly within the surrounding content rather than collapsing them behind a menu or pushing them onto a separate screen. Instead of a single summary row that you tap to reveal options, every option appears as its own selectable row in place, with the current selection marked. Reach for this style inside a List or Form when you want the available choices to stay visible and immediately tappable as part of the scrolling content.
Apply the style with pickerStyle(.inline)
You don't construct
InlinePickerStyledirectly. Instead, attach the.pickerStyle(.inline)modifier to aPicker, where.inlineis the shorthand forInlinePickerStyle. In the example,.pickerStyle(.inline)hangs off thePicker("Flavor", selection: $flavor), telling that picker to render its options as inline rows.Bind the selection to drive the marked row
The style needs a selection binding so it knows which inline row to mark as chosen. The
Picker'sselectionparameter takes a binding such as$flavor, backed here by the@State private var flavor; whichever option's tag matches that value is shown as selected, and tapping a different row writes the new value back through the binding.Provide one option per row with tag(_:)
Each view in the picker's content becomes its own inline row, and
tag(_:)gives each one the identity that's compared against the selection. The threeTextviews —Text("Vanilla").tag("Vanilla"),Text("Chocolate"), andText("Strawberry")— each carry aStringtag matching the type offlavor, so the inline style can highlight the right one.Embed the picker in a List or Form
InlinePickerStyleis designed for container contexts and reads its appearance from the enclosing list or form. Placing thePickerinsideListlets the inline rows blend into the surrounding rows and adopt the list's separators, insets, and section styling rather than floating on their own.
.pickerStyle(.inline) to .pickerStyle(.menu) and notice the three options collapse into a single tappable summary row, making clear how the inline style spreads those same choices out as visible rows.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct InlinePickerStyleDemo: View {
@State private var flavor = "Vanilla"
var body: some View {
List {
Picker("Flavor", selection: $flavor) {
Text("Vanilla").tag("Vanilla")
Text("Chocolate").tag("Chocolate")
Text("Strawberry").tag("Strawberry")
}
.pickerStyle(.inline)
}
}
}