Skip to content

Instantly share code, notes, and snippets.

@atrinh0
Created June 27, 2021 17:44
Show Gist options
  • Save atrinh0/aca74b9200bc15f856a17027aeeb6429 to your computer and use it in GitHub Desktop.
Save atrinh0/aca74b9200bc15f856a17027aeeb6429 to your computer and use it in GitHub Desktop.
Picker Menu Style Label Issue
import SwiftUI
struct ContentView: View {
let options: [String] = ["ascending", "descending", "highest", "lowest"]
@State private var selectedOption = "ascending"
var body: some View {
NavigationView {
VStack {
Text("Image label")
Picker(selection: $selectedOption, label: Image(systemName: "line.horizontal.3.decrease")) {
ForEach(options, id: \.self) {
Text($0)
}
}
.pickerStyle(MenuPickerStyle())
Text("Text label")
Picker(selection: $selectedOption, label: Text("sort")) {
ForEach(options, id: \.self) {
Text($0)
}
}
.pickerStyle(MenuPickerStyle())
Text("Leading string")
Picker("sort", selection: $selectedOption) {
ForEach(options, id: \.self) {
Text($0)
}
}
.pickerStyle(MenuPickerStyle())
Spacer()
}
.navigationBarItems(leading:
Picker(selection: $selectedOption, label: Image(systemName: "line.horizontal.3.decrease")) {
ForEach(options, id: \.self) {
Text($0)
}
}
.pickerStyle(MenuPickerStyle())
, trailing:
Picker(selection: $selectedOption, label: Text("sort")) {
ForEach(options, id: \.self) {
Text($0)
}
}
.pickerStyle(MenuPickerStyle())
)
}
.navigationViewStyle(StackNavigationViewStyle())
}
}
@cyrillelegrand
Copy link

Seems fixed in beta 5.

@atrinh0
Copy link
Author

atrinh0 commented Aug 11, 2021

Seems fixed in beta 5.

@cyrillelegrand still the same for me on beta 5 (on a physical device as well as simulator via Xcode 13 beta 5).

I have updated my app above with a workaround, to convert the picker (with a menu style) to use a menu (with a picker).

Same workaround is seen here: atrinh0/covid19@9e96738

@atrinh0
Copy link
Author

atrinh0 commented Sep 15, 2021

Issue still exists in iOS 15 RC, and on Xcode 13 RC.

@atrinh0
Copy link
Author

atrinh0 commented Aug 13, 2022

Issue remains in Xcode 14 beta 5, the picker shows the up/down arrows instead of using the label or leading titleKey defined.

@felix-schindler
Copy link

Thanks for the workaround!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment