struct ContentView: View {
var colors = ["Red", "Green", "Blue", "Tartan"]
@State private var selectedColor = "Red"
var body: some View {
VStack {
Picker("Please choose a color", selection: $selectedColor) {
ForEach(colors, id: \.self) {
Text($0)
}
}
.accentColor(.red)
Text("You selected: \(selectedColor)")
}
}
}
搞不懂这里用 foregroundStyle
为什么无效!