【发布时间】:2020-10-31 12:43:02
【问题描述】:
我的SwiftUI View 中有一个Picker 和新的MenuPickerStyle。
如您所见,选择器的标签与选项相同,从一个选项更改为另一个选项时会变暗。
看起来它是不可点击的,但是当点击它时它会完成所需的工作。
这是我的代码。这只是一个非常简单的选择器实现。
struct MenuPicker: View {
@State var selection: String = "one"
var array: [String] = ["one", "two", "three", "four", "five"]
var body: some View {
Picker(selection: $selection, label: Text(selection).frame(width: 100), content: {
ForEach(array, id: \.self, content: { word in
Text(word).tag(word)
})
})
.pickerStyle(MenuPickerStyle())
.padding()
.background(Color(.systemBackground).edgesIgnoringSafeArea(.all))
.cornerRadius(5)
}
}
struct ContentView: View {
var body: some View {
ZStack {
Color.gray
MenuPicker()
}
}
}
【问题讨论】: