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())
}
}
@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