I have been trying for quite some time to add a custom button style/behavior to the label of a SwiftUI Menu() but haven't had any success so far. Here is an example of what I want to achieve:
Custom Button Style
Let's assume I have a custom Button Style that lets a button's text become red when pressed.
struct RedButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.foregroundColor(configuration.isPressed ? .red : .primary)
}
Menu
Also, I have a standard SwiftUI menu.
Menu("Menu button", content: {
// Some menu content goes here
})
In this configuration the SwiftUI menu displays a standard button in the accent color (system blue) that behaves like a standard button (getting greyed out when pressed). When pressed, the menu is shown as expected.
Custom menu button
Now I want to somehow apply the custom button style to the button the menu is using. What I tried was the following:
Menu(content: {
// Some menu content goes here
}, label: {
Button("Menu button", action: { })
.buttonStyle(RedButtonStyle())
})
However, the behavior of the menu's button is not changing at all - it's still just getting greyed out when being pressed, not getting colored red.
I also experimented a bit with creating a custom MenuStyle but haven't had any success so far.
Any suggestions on this? Thanks!

