Search code examples
macosswiftuimenu

SwiftUI how to color a menu button icon in macOS


In macOS i want to color the Image that opens the menu, whatever i do i just get the text colored icon

enter image description here

Menu {
   Button {

   } label: {
      Text("Some item")
   }
} label: {
   Image(systemName: "chevron.down.circle.fill")
      .foregroundColor(.red)
}
.menuStyle(.borderlessButton)
.menuIndicator(.hidden)
.foregroundColor(.blue)
.fixedSize(horizontal: true, vertical: false)

how to color the icon like this

enter image description here


Solution

  • You can replace your foregroundColor modifier with a foregroundStyle with two colors, to use palette rendering:

    Menu {
       Button {
    
       } label: {
          Text("Some item")
       }
    } label: {
       Image(systemName: "chevron.down.circle.fill")
          .foregroundStyle(.white, .green)
    }