Hello,
I presents a View inside a NavigationView. I use the .toolbar modifier to set a navigation bar items. One of them must be in red as it represents a destructive action.
.toolbar(content: {
ToolbarItem(placement: .navigationBarLeading) {
Button { } label: {
Text("Delete").foregroundColor(.red)
}
}
}
How can we set a foregroundColor/fontWeight for a Button in a ToolBarItem? I've tried to set a custom ButtonStyle, foregroundColor to the Text, foregroundColor to the Button.
Resolved in iOS & iPadOS 15 beta 2
Buttons in toolbar items now respect custom styles or customizations to their labels.
This means that you can customise the appearance of toolbar buttons however you like.
If you wanted the destructive red style button, you can specify a role for the button, like this:
Button(role: .destructive) {
…
} label: {
…
}
NOTE: This will only work with iOS 15, macOS 12 and similar.