0

My currently have a NavigationView with an embedded ToolbarItemGroup containing buttons with SF Symbols. I'm attempting to change the Trash button's color to that of red.

var body: some View {
    NavigationView {
        Text("Hello, World!")
            .navigationTitle("Today")
            .toolbar {
                ToolbarItemGroup(placement: .navigationBarTrailing) {
                    Button(action: {
                        print("Add button was tapped")
                    }) {
                        HStack {
                            Image(.add)
                        }
                    }
                    
                    Button(action: {
                        print("Trash button was tapped")
                    }) {
                        HStack {
                            Image(.trash)
                                .foregroundColor(.red)
                                .accentColor(.red)
                        }
                    }
                    .foregroundColor(.red)
                    .accentColor(.red)
                }
            }
    }
    
    
}

I can't seem to set the color of the Trash image symbol to red. Image(.trash) is no typo, I'm using this extension I wrote!

Thanks :)

JDev
  • 5,168
  • 6
  • 40
  • 61
  • Does this answer your question? [How can I set an image tint in SwiftUI?](https://stackoverflow.com/questions/61152480/how-can-i-set-an-image-tint-in-swiftui) – shim Jul 08 '21 at 17:50
  • Unfortunately not. None of the solutions seem to affect NavigationView symbols. – JDev Jul 08 '21 at 18:03
  • Does [using an inline menu](https://stackoverflow.com/a/65027625/14956277) with a custom style work for you? – D M Jul 08 '21 at 19:55

2 Answers2

2

You can add .accentColor(.red) to the NavigationView. Although it will change the color of all ToolBar Items. An example would be

NavigationView {
 SomeViews
}
.accentColor(.red)

It did the trick, as shown here enter image description here

Visal Rajapakse
  • 1,718
  • 1
  • 9
  • 15
0

An other way to work on NavigationView. Although it will change the color of all ToolBar Items, too.

struct ContentView: View {

   init() {
        UINavigationBar.appearance().tintColor = UIColor.magenta
   }

   // your code follows
}
dengST30
  • 3,643
  • 24
  • 25