1

In my code below I am trying to have both views with the systemImage "line.3.horizontal.circle.fill" be green. But the view as a toolbaritem is showing as default blue. I can currently on the new Xcode and running on iOS 17

struct SwiftUITestView: View {
    var body: some View {
        NavigationStack{
            HStack{
                Text("test")
                Menu{
                    Button{
                        print("test")
                    }label:{
                        Text("test")
                    }
                } label:{
                    Label("Filter", systemImage: "line.3.horizontal.circle.fill")
                        .foregroundStyle(.green)
                        .frame(width: 20, height: 20)
                        
                }
                .menuActionDismissBehavior(.disabled)
                
            }
            .toolbar(content: {
                ToolbarItem(placement: .topBarTrailing) {
                            Menu{
                                Button{
                                    print("test")
                                }label:{
                                    Text("test")
                                }
                            } label:{
                                Label("Filter", systemImage: "line.3.horizontal.circle.fill")
                                    .foregroundStyle(.green)
                                    .frame(width: 20, height: 20)
                            }
                            .menuActionDismissBehavior(.disabled)
                }
            })
        }

    }

}

I'm wanting both of the Labels to be green

Zach
  • 33
  • 1
  • 6

1 Answers1

0

Don't use .accentColor as others may have suggested, as that is being deprecated. You can use .tint outside of the menu definition like so:

ToolbarItem(placement: .topBarTrailing) {
                        Menu{
                            Button{
                                print("test")
                            }label:{
                                Text("test")
                            }
                        } label:{
                            Label("Filter", systemImage: "line.3.horizontal.circle.fill")
                                .foregroundStyle(.green)
                                .frame(width: 20, height: 20)
                        }
                        .tint(.green)
                        .menuActionDismissBehavior(.disabled)
            }

Tested and working on an iOS 17 Simulator in Xcode 15 Beta 2.0 (15A5161b)