article

Sunday, November 14, 2021

SwiftUI Swipe Actions - swipeActions in SwiftUI

SwiftUI Swipe Actions - swipeActions in SwiftUI

ContentView.swift
 
//
//  ContentView.swift
//  swiftuidev15ios
//
//  Created by Cairocoders
//

import SwiftUI

struct ContentView: View {
    
    var body: some View {
        
        List{
            ForEach(1...15, id: \.self) { index in
                
                Text("List \(index)")
                    .swipeActions(edge: .leading) {
                    Button {
                            //action
                    } label: {
                        if index % 2 == 0 {
                            Label("Read", systemImage: "envelope.open")
                        }else {
                            Label("Unread", systemImage: "envelope.badge")
                        }
                    }
                }
                    .swipeActions(edge: .trailing) {
                        Button(role: .destructive) {
                            //action
                        } label: {
                            Label("Delete", systemImage: "trash")
                        }
                        Button {
                            //action
                        } label: {
                            Label("Flag", systemImage: "flag")
                        }
                    }
            }//end foreach
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Related Post