Why is there no custom label displayed? Thanks for an answer.
struct ContentView: View{
@State var selection = 0
let numbers = [1,2,3,4,5]
var body: some View{
Picker(selection: $selection, content: {
ForEach(numbers,id:\.self){i in
Text("Number \(i)").tag(i)
}
}, label: {
Text("\(selection)")
.padding()
.background(Circle().foregroundColor(.red))
})
.pickerStyle(MenuPickerStyle())
}
}
A Picker
with the .menu
picker style won't use the view specified in the label
closure. It will generate its label based off of the currently selected item. This is the default behaviour.
If you want a custom label, use a standard Menu
and add your Picker
inside of that. Note, you won't get the iOS 16 style double chevron indicator.