宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
//  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?()
        }
        
    }
 
}