在 Picker 中显示多个视图

Display Multiple views in Picker

我试图在所选选项旁边的 Picker 中显示文字,但这些文字从未正确显示。我希望用户能够单击文本也能够打开 Picker。我尝试将文本放在选择器之外,这会导致正确显示,但文本不可点击。 我正在使用 Xcode 13 Beta 5iOS15.

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

Picker 的图片,文字在 Picker 之外

根据我的要求所做的调整如下所示。任何放在标签内的东西现在都可以点击。

Menu {
    Picker(selection: $fruit, label: EmptyView()) {
        ForEach(fruits, id: \.self) { fruit in
            Text(fruit)
        }
    }
} label: {
      HStack {
          Image(systemName: "hand.thumbsup.fill")
          Text("Picked: \(fruit)")
      }
}

使用带有内联 PickerMenu 作为其内容:

Menu {
    Picker(selection: $fruit, label: EmptyView()) {
        ForEach(fruits, id: \.self) { fruit in
            Text(fruit)
        }
    }
    .labelsHidden()
    .pickerStyle(InlinePickerStyle())
} label: {
    HStack {
        Text("Picked:")
        Text(fruit)
    }
}