//
|
// YYAlertViewController.swift
|
// WashCar
|
//
|
// Created by alvin_y on 2020/7/10.
|
// Copyright © 2020 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
|
typealias onCancelBlock = () -> Void
|
|
class YYAlertViewController: YYViewController {
|
|
@IBOutlet weak var label_title: UILabel!
|
@IBOutlet weak var label_content: UILabel!
|
@IBOutlet weak var button_cancel: UIButton!
|
@IBOutlet weak var button_done: UIButton!
|
|
var alertTitle: String?
|
var textFieldText: String?
|
var alertCancelTitle: String?
|
var alertDoneTitle: String?
|
var isAutoDismiss: Bool = true
|
|
var onDone: onDoneBlock?
|
|
var onCancel: onCancelBlock?
|
|
init() {
|
super.init(nibName: String(describing: YYAlertViewController.self), bundle: Bundle.main)
|
|
modalTransitionStyle = .crossDissolve
|
modalPresentationStyle = .overFullScreen
|
|
|
}
|
|
required init?(coder aDecoder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
|
class func display(title: String?, text: String?, cancelTitle: String?, doneTitle: String?, isAutoDismiss: Bool = true,onDone: @escaping () -> Void,onCancel: @escaping (() -> Void)) {
|
let vc = YYAlertViewController()
|
vc.alertTitle = title
|
vc.textFieldText = text
|
vc.alertCancelTitle = cancelTitle
|
vc.alertDoneTitle = doneTitle
|
vc.isAutoDismiss = isAutoDismiss
|
vc.onDone = onDone
|
vc.onCancel = onCancel
|
self.base()?.present(vc, animated: true, completion: nil)
|
}
|
|
class func display(title: String?, text: String?, cancelTitle: String?, doneTitle: String?, isAutoDismiss: Bool = true,onDone: @escaping () -> Void) {
|
let vc = YYAlertViewController()
|
vc.alertTitle = title
|
vc.textFieldText = text
|
vc.alertCancelTitle = cancelTitle
|
vc.alertDoneTitle = doneTitle
|
vc.isAutoDismiss = isAutoDismiss
|
vc.onDone = onDone
|
self.base()?.present(vc, animated: true, completion: nil)
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
view.backgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.7)
|
label_title.text = alertTitle
|
label_content.text = textFieldText
|
button_cancel.setTitle(alertCancelTitle, for: .normal)
|
button_done.setTitle(alertDoneTitle, for: .normal)
|
}
|
|
|
@IBAction func didPressCancelButton(_ sender: UIButton) {
|
|
if isAutoDismiss {
|
dismiss(animated: true) { [unowned self] in
|
self.onCancel?()
|
}
|
} else {
|
onCancel?()
|
}
|
|
|
}
|
|
@IBAction func didPressDoneButton(_ sender: UIButton) {
|
if isAutoDismiss {
|
dismiss(animated: true) { [unowned self] in
|
self.onDone?()
|
}
|
} else {
|
onDone?()
|
}
|
|
}
|
|
}
|