article

Wednesday, March 16, 2022

SwiftUI Alert - SPAlert Package

SwiftUI Alert - SPAlert Package

SPAlert https://github.com/ivanvorobei/SPAlert

ContentView.swift
 
//
//  ContentView.swift
//  SwiftUIProject
//
//  Created by Cairocoders
//

import SwiftUI
import SPAlert

struct ContentView: View {
    @State var showAlert = false
    @State var showAlert2 = false
    
    
    var body: some View {
        VStack(spacing: 20) {
            Button("Show Alert") {
                showAlert.toggle()
            }
            .SPAlert(
                isPresent: $showAlert,
                message: "SwiftUI Alert - SPAlert Package",
                duration: 1.0)
            
            Button("Show Alert 2") {
                showAlert2.toggle()
            }
            .SPAlert(
                isPresent: $showAlert2,
                title: "SPAlert Package",
                message: "This tutorial has been completed",
                duration: 2.0,
                dismissOnTap: false,
                preset: .done,
                //preset: .custom(UIImage(systemName: "checkmark.seal.fill")!),
                haptic: .success,
                layout: .init(),
                completion: {
                    print("This is a completion log.")
                    showAlert.toggle()
                })
            .tint(.orange)
        }
    }
}

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

Related Post