How it works
PickerStyle defines the appearance and interaction model of a picker, letting you choose among presentations like a segmented control, a pop-up menu, or an inline list without changing the picker's data or selection binding. Rather than conforming to the protocol yourself, you select one of SwiftUI's built-in styles and apply it with the pickerStyle(_:) modifier. Reach for it when the default picker presentation doesn't fit a screen's density or platform conventions, or when you want a control's look to adapt to the container it sits in.
Apply a style with the pickerStyle(_:) modifier
PickerStyle takes effect through the pickerStyle(_:) view modifier, which you attach to a Picker. The modifier sets the style for that picker and any pickers nested below it in the view tree. In the example, each Picker over flavors is given its own presentation by a separate .pickerStyle call.
Pick a concrete style value
You don't construct a PickerStyle directly; instead you pass one of the standard conforming values exposed as static members. The example reaches for three: .segmented renders a horizontal segmented control, .menu presents the choices in a pop-up menu, and .inline lays the options out directly within the surrounding container.
Keep the selection binding independent of the style
The chosen PickerStyle only governs presentation, so the picker's selection: binding and its content stay the same across styles. Here every Picker drives the same $flavor state through identical ForEach options, and switching from .segmented to .menu to .inline changes how the control looks while the bound value continues to flow unchanged.
Let the container shape automatic behavior
Some styles, including the default .automatic, resolve their final look from the context the picker lives in, such as a Form, list, or toolbar. Placing the pickers inside Form gives SwiftUI the surrounding layout it uses to render row-style and inline presentations appropriately on each platform.
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 PickerStyleDemo: View {
@State private var flavor = "Vanilla"
let flavors = ["Vanilla", "Chocolate", "Strawberry"]
var body: some View {
Form {
Picker("Segmented", selection: $flavor) {
ForEach(flavors, id: \.self) { Text($0) }
}
.pickerStyle(.segmented)
Picker("Menu", selection: $flavor) {
ForEach(flavors, id: \.self) { Text($0) }
}
.pickerStyle(.menu)
Picker("Inline", selection: $flavor) {
ForEach(flavors, id: \.self) { Text($0) }
}
.pickerStyle(.inline)
}
.padding()
}
}