I'm trying to customise color of icon in swipeAction of SwiftUI. Outside foregroundColor() it works, inside, - not.
Button {
print("Hello")
} label: {
Label(
title: {},
icon: {
Image(systemName: "checkmark")
.foregroundColor(.purple) // It makes checkmark red
}
)
}
if #available(iOS 15.0, *) {
Text("Text").swipeActions {
Button {
print("Hello")
} label: {
Label(
title: {},
icon: {
Image(systemName: "checkmark")
.foregroundColor(.purple) // It doesn't change anything
}
)
}
}
}
A swipe action has its own styling that is applied by the system. According to the documentation:
You can add color by adding the
.tint()modifier.Note: The color red is used by default for destructive actions (like delete) and should be avoided for non-destructive actions. If your action is destructive, use
Button(role: .destructive)and the system will color it red if you don’t apply.tint().Check the documentation for more information about swipeActions.