6

I have menu items at the leading and trailing edges of the NavigationBar. I am not able to change the color of the menu items. I am, however able to change the color of the icon of the Navigation bar itself but not the menu items that are under the navigation bar. For example, I would like the "delete" to show up in red. I tried to create a ConfigurationStyle but with no luck.

I have two menu items on each side: On the leading edge, I have a "New" and "Edit" and was trying to change the color to green On the trailing edge, I have "Add" and "Delete"

What am I doing wrong? Any help is very much appreciated. Thanks.

Here is an example code of what I am trying to do.

struct HomeView: View {
    var body: some View {
        NavigationView {
            Text("Hello World")
                .navigationTitle("Title")
                .navigationBarItems(leading: {
                    Menu {
                        Button(action: {}) {
                            Label {
                                Text("New")
                            } icon: {
                                Image(systemName: "pencil")
                            }
                        }.foregroundColor(.green) //tried on the Menu item but does not work
                        Button(action: {}) {
                            Label {
                                Text("Edit").foregroundColor(.green) //tried to change color for individual elements (does not work)
                            } icon: {
                                Image(systemName: "square.and.pencil") // tried to change just for the image (does not work)
                                    .foregroundColor(.green)
                            }
                        }
                    } label: {
                        Image(systemName: "ellipsis.circle").foregroundColor(.green) //this works!!!
                    }
                }(), trailing: {
                    Menu {
                        Button(action: { }) { // tried to change color on the whole button with a MenuStyle (does not work)
                            Label("Add", systemImage: "plus")
                        }.menuStyle(RedMenu())
                        Button(action: { }) {
                            Label("Delete", systemImage: "trash") // tried to change the color on the Label (does not work)
                                .foregroundColor(.red)
                        }
                    } label: {
                        Image(systemName: "plus")
                    }
                }())
        }
        .navigationBarTitleDisplayMode(.inline)
        .navigationViewStyle(StackNavigationViewStyle())
    }
}

tried with MenuStyle but no luck

struct RedMenu: MenuStyle {
    func makeBody(configuration: Configuration) -> some View {
        Menu(configuration)
            .foregroundColor(.red)
    }
}
RXP
  • 517
  • 4
  • 18

0 Answers0