4

I'm trying to modify the color of the Image in the swipe action of a list in SwiftUI.

I have tried a few things:

  • Setting the image with rendering template and after that applied the foregroundColor modifier
  • Setting foregroundColor modifier directly to button
  • Tried to set a custom image

I searched a lot for this, and I didn't found anything, not only didn't found solution, I didn't found a NO, like "You can't do that", so this question is for me and anyone in the future trying to do the same thing and they being able to found a quick solution or a quick "Thats impossible".

A piece of my code, really simple:

                List {
                    if viewModel.showSkeleton {
                        ForEach(0...4, id: \.self) { _ in
                            SkeletonTransactionRowView().listRowSeparator(.hidden)
                        }
                    } else {
                        ForEach(viewModel.transactions) { transaction in
                            TransactionRowView(transaction: transaction)
                                .swipeActions {
                                    Button { viewModel.delete(transaction: transaction) } label: {
                                        Label("Delete", systemImage: "trash")
                                    }
                                    .tint(.red)
                                }
                            
                        }
                        .listRowSeparator(.hidden)
                    }
                }
                .listStyle(PlainListStyle())

NOTE: I know i can make a custom drag gesture and do all this stuff manually, but I want to know if it's possible to do it with the swipe action modifier.

Alessandro Pace
  • 206
  • 4
  • 8
  • 1
    For your case you can use `Button(role: .destructive)` which will make it red automatically. Other than that I have the same questions.. any news? – thisIsTheFoxe Mar 07 '22 at 21:25
  • Hi @thisIsTheFoxe nothing new, im still working in the project, so if i get a good solution i will post it here! Thx for the commnet! – Alessandro Pace Mar 07 '22 at 23:13

0 Answers0