0

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
                            }
                        )
                    }
                }
            }
Konstantin.Efimenko
  • 1,242
  • 1
  • 14
  • 38

1 Answers1

1

A swipe action has its own styling that is applied by the system. According to the documentation:

For labels or images that appear in swipe actions, SwiftUI automatically applies the fill symbol variant

You can add color by adding the .tint() modifier.

Text("Text").swipeActions {
    Button {
        print("Hello")
    } label: {
        Label("Choose", systemImage: "checkmark")
    }
    .tint(.green)
}

Showing tint color in simulator


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.

vacawama
  • 150,663
  • 30
  • 266
  • 294