
我想要一個常量標簽,但是我的選擇器標簽會根據我選擇的值而改變。
我的代碼:
Picker(
selection : $textBoxes[currentIndex].textFont,
label : Text("Font"),
content : {
Text("LuxuriousRoman-Regular").tag("LuxuriousRoman-Regular")
Text("Merriweather-Regular").tag("Merriweather-Regular")
Text("Neonderthaw-Regular").tag("Neonderthaw-Regular")
Text("OpenSansCondensed-Light").tag("OpenSansCondensed-Light")
Text("Pacifico").tag("Pacifico")
Text("PTSans-Regular").tag("PTSans-Regular")
Text("RobotoMono-VariableFont_wght").tag("RobotoMono-VariableFont_wght")
Text("SedgwickAve-Regular").tag("SedgwickAve-Regular")
}
).pickerStyle(MenuPickerStyle())
uj5u.com熱心網友回復:
當使用Picker在其選單風格形式,在label沒有得到展示,而是所選擇的專案時,如您所見。
如果你想使用標準標簽,你應該使用Menu作為基本視圖,然后使用 aPicker作為選單的內容。例如,您可以在此處看到用法上的差異:
struct ContentView: View {
enum DemoOption: String, CaseIterable {
case one, two, three, four, five
}
@State private var pickerValue: DemoOption = .one
@State private var menuValue: DemoOption = .two
var body: some View {
VStack {
Picker("Picker Option", selection: $pickerValue) {
ForEach(DemoOption.allCases, id: \.rawValue) { option in
Text(option.rawValue).tag(option)
}
}
.pickerStyle(.menu)
Menu {
Picker("Choose an option", selection: $menuValue) {
ForEach(DemoOption.allCases, id: \.rawValue) { option in
Text(option.rawValue).tag(option)
}
}
} label: {
Text("Choose an option")
}
}
}
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/421123.html
標籤:
上一篇:如何快速回呼管理器類中的委托方法
