I am trying to display words in a Picker
next to the selected option but the words are never displayed correctly. I want the user to be able to click the text to be able to open the Picker
as well. I have tried putting the text outside the picker which leads to displaying correctly but the text is not clickable.
I am using Xcode 13 Beta 5 and iOS15.
struct ContentView: View {
@State var fruit = "Apple"
let fruits = ["Apple","Orange","Pear","Grape"]
var body: some View {
HStack {
Picker(selection: $fruit) {
Text("Picked:")
ForEach(fruits, id: \.self){ fruit in
Text(fruit)
}
} label: {
Text("")
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Picture for Picker
with text outside of Picker
Tweaks made to fit what I asked are shown below. Any thing put inside label is now clickable.
Menu {
Picker(selection: $fruit, label: EmptyView()) {
ForEach(fruits, id: \.self) { fruit in
Text(fruit)
}
}
} label: {
HStack {
Image(systemName: "hand.thumbsup.fill")
Text("Picked: \(fruit)")
}
}