I have the following test code
import SwiftUI
struct ContentView: View {
@State private var field1 = ""
@State private var field2 = ""
@State private var field3 = ""
var body: some View {
VStack {
Form {
Section(header: Text("Input Fields")) {
TextField("Field 1", text: $field1)
TextField("Field 2", text: $field2)
TextField("Field 3", text: $field3)
}
}
List {
ForEach(1..<6) { index in
Text("Item \(index)")
}
}
.listStyle(InsetListStyle())
}
.navigationTitle("Form and List View")
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Dismiss") {
// Handle dismiss action
}
.foregroundStyle(.red) //
}
ToolbarItem(placement: .primaryAction) {
Button("Done") {
// Handle done action
}
.foregroundStyle(.green) //
}
}
}
}
I can't customize the color of the Buttons. Besides .foreground modifier I have tried ..foregroundColor(.red) and .foregroundColor(.green) to no avail. How can I customize the buttons in the toolbar for both macOS and IOS