如何使样式化的选择器完全可触摸
How to make styled picker fully touchable
我按以下方式设置了选择器的样式:
Picker(selection: $selectedProduct, label: Text("Product: \(self.products[self.selectedProduct].name!)")) {
ForEach(0 ..< roles.count) {
Text(products[[=10=]].name!)
.frame(minWidth: 0, maxWidth: .infinity)
}
}
.animation(nil)
.frame(minWidth: 0, maxWidth: .infinity)
.font(.headline)
.foregroundColor(Color.white)
.padding()
.background(Color(UIColor(.blue)))
.cornerRadius(15.0)
.pickerStyle(MenuPickerStyle())
这将生成我想要的样式,如下所示:
遗憾的是只有标签周围的区域是可触摸的:
我不知道如何让整个东西都可以触摸。我错过了什么吗?
如有任何帮助,我们将不胜感激。
尝试将所有 size/frame 相关修饰符应用于内部标签,而不是选择器本身,例如
Picker(selection: $selectedProduct, label:
Text("Product: \(self.products[self.selectedProduct].name!)")
.frame(minWidth: 0, maxWidth: .infinity)
.font(.headline)
.foregroundColor(Color.white)
.padding()
.background(Color(UIColor(.blue)))
.cornerRadius(15.0)
) {
ForEach(0 ..< roles.count) {
Text(products[[=10=]].name!)
.frame(minWidth: 0, maxWidth: .infinity)
}
}
.animation(nil)
.pickerStyle(MenuPickerStyle())
我按以下方式设置了选择器的样式:
Picker(selection: $selectedProduct, label: Text("Product: \(self.products[self.selectedProduct].name!)")) {
ForEach(0 ..< roles.count) {
Text(products[[=10=]].name!)
.frame(minWidth: 0, maxWidth: .infinity)
}
}
.animation(nil)
.frame(minWidth: 0, maxWidth: .infinity)
.font(.headline)
.foregroundColor(Color.white)
.padding()
.background(Color(UIColor(.blue)))
.cornerRadius(15.0)
.pickerStyle(MenuPickerStyle())
这将生成我想要的样式,如下所示:
遗憾的是只有标签周围的区域是可触摸的:
我不知道如何让整个东西都可以触摸。我错过了什么吗?
如有任何帮助,我们将不胜感激。
尝试将所有 size/frame 相关修饰符应用于内部标签,而不是选择器本身,例如
Picker(selection: $selectedProduct, label:
Text("Product: \(self.products[self.selectedProduct].name!)")
.frame(minWidth: 0, maxWidth: .infinity)
.font(.headline)
.foregroundColor(Color.white)
.padding()
.background(Color(UIColor(.blue)))
.cornerRadius(15.0)
) {
ForEach(0 ..< roles.count) {
Text(products[[=10=]].name!)
.frame(minWidth: 0, maxWidth: .infinity)
}
}
.animation(nil)
.pickerStyle(MenuPickerStyle())