我正在尝试在Picker
所选选项旁边显示单词,但这些单词从未正确显示。我希望用户能够单击文本也能够打开Picker
。我尝试将文本放在选择器之外,这会导致正确显示,但文本不可点击。我正在使用Xcode 13 Beta 5和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()
}
}
根据我的要求进行的调整如下所示。任何放在标签内的东西现在都可以点击了。
Menu {
Picker(selection: $fruit, label: EmptyView()) {
ForEach(fruits, id: \.self) { fruit in
Text(fruit)
}
}
} label: {
HStack {
Image(systemName: "hand.thumbsup.fill")
Text("Picked: \(fruit)")
}
}