3

screenshot

How Can I add multiple custom buttons in a list on swipe?

byaruhaf
  • 4,128
  • 2
  • 32
  • 50
Mr .K
  • 51
  • 2
  • This is not supported in swiftUI at the moment check this answer https://stackoverflow.com/questions/57112426/swiftui-custom-swipe-actions-in-list – byaruhaf Jul 14 '20 at 15:07

2 Answers2

0

You can use swipeActions, but are only supported for target iOS >=15

https://developer.apple.com/documentation/swiftui/view/swipeactions(edge:allowsfullswipe:content:)

Cristian Zumelzu
  • 842
  • 10
  • 15
0

You can achieve that by using swipeActions modifier (iOS 15.0+), here is the example:

List {
    ForEach(items, id: \.self) { item in
        Text("Item N\(item)")
    }
    .swipeActions(edge: .trailing) {
        Button(role: .destructive) {
            print("Delete")
        } label: {
            Text("Delete")
                .foregroundColor(.white)
        }
        .tint(.red)
        
        Button(role: .cancel) {
            print("Edit")
        } label: {
            Text("Edit")
                .foregroundColor(.white)
        }
        .tint(.gray)

    }
}
narek.sv
  • 845
  • 5
  • 22