当前位置:网站首页>Alert pop up & sheet share view

Alert pop up & sheet share view

2020-12-07 09:02:40 Sword dragon Yuwu

//
//  WYAlertController.swift
//  DYWX
//
//  Created by  Wang Wu  on 2020/11/26.
//

import UIKit

class WYAlertController {
    ///  bounced 
    static func wy_showAlertView(currentController: UIViewController, title: String, message: String
                                 , confirmTitle: String, cancelTitle: String,
                                 confirmHandle: @escaping (UIAlertAction) -> Void, cancelHandle: @escaping (UIAlertAction) -> Void) {
        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
        //  Cancel button 
        let cancel = UIAlertAction(title: cancelTitle, style: .default) { (action) in
            cancelHandle(action)
        }
        //  OK button 
        let confirm = UIAlertAction(title: confirmTitle, style: .default) { (action) in
            confirmHandle(action)
        }
        alert.addAction(confirm)
        alert.addAction(cancel)
        
        currentController.present(alert, animated: true, completion: nil)
    }
    ///
    static func wy_showSheetView(currentController: UIViewController, title: String, message: String, actionArray: [String],
                                 confirmTitle:String, cancelTitle: String,
                                 actionHandle: @escaping (UIAlertAction) -> Void, cancelHandle: @escaping (UIAlertAction) -> Void) {
        let sheet = UIAlertController(title: title, message: message, preferredStyle: .actionSheet)
        actionArray.forEach { (item) in
            let action = UIAlertAction(title: item, style: .default) { (action) in
                actionHandle(action)
            }
            sheet.addAction(action)
        }
        //  Cancel button 
        let cancel = UIAlertAction(title: cancelTitle, style: .cancel) { (action) in
            cancelHandle(action)
        }
        sheet.addAction(cancel)
        
        currentController.present(sheet, animated: true, completion: nil)
    }
}

版权声明
本文为[Sword dragon Yuwu]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201207085507047g.html