Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI: How to set foregroundColor on menu button

Tags:

swiftui

I would like to make a menu button red as it carries a destructive nature, but my implementation doesn't override the foreground color at all.

Code.

ToolbarItem(placement: .navigationBarTrailing) {
    Menu {
        Button(action: {}) {
           Label("Delete", systemImage: "trash")
               .foregroundColor(.red)
        }
    }
    label: {
        Text("Next")
    }
}

Other attempts:

ToolbarItem(placement: .navigationBarTrailing) {
    Menu {
        Button(action: {}) {
           Label("Delete", systemImage: "trash")
        }
        .foregroundColor(.red)
    }
    label: {
        Text("Next")
    }
}

Results

enter image description here

Noticed that the "Delete" button is not red.

like image 745
Koh Avatar asked Oct 17 '25 02:10

Koh


1 Answers

Not sure about older iOS but it's possible from iOS 15

Menu("Actions") {
    Button(role: .destructive, action: { }) {
        Label("Delete", systemImage: "trash")
    }
}

Result

like image 53
Spaghetti Avatar answered Oct 19 '25 12:10

Spaghetti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!