How to customize buttons in a SwiftUI view toolbar

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

Hi @BigEagle ,

Have you tried using the .tint() modifier? You would use it like this:

NavigationStack {
   List {
     //code here
  }
     .navigationTitle("Form and List View")
     .toolbar {
            ToolbarItem(placement: .cancellationAction) {
                 Button("Dismiss") {
                        // Handle dismiss action
                 }
               }
             ToolbarItem(placement: .primaryAction) {
                  Button("Done") {
                      // Handle done action
                   }

              }
      }
      .tint(.green)
}

Yes I add tried the .tint modifier as well with no success. BTW I am using Xcode 15 beta 7, I think I will give a try with my Ventura Xcode 14 to see if that makes a difference.

I get the same results on Ventura and Xcode 14

How to customize buttons in a SwiftUI view toolbar
 
 
Q