How can we add two custom button in swiping List - SwiftUI?

Viewed 372

screenshot

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

2 Answers

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)

    }
}
Related