宽窄优行-由【嘉易行】项目成品而来
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
//
//  YYAlertOKViewController.swift
//  WashCar
//
//  Created by alvin_y on 2020/7/9.
//  Copyright © 2020 yangwang. All rights reserved.
//
 
import UIKit
 
typealias onDoneBlock = () -> Void
 
class YYAlertOKViewController: YYViewController {
    @IBOutlet weak var topConstraint: NSLayoutConstraint!
    
    /// 分割线
    @IBOutlet weak var view_line: UIView!
    
    /// 关闭
    @IBOutlet weak var button_close: UIButton!
    
    /// 标题
    @IBOutlet weak var label_title: UILabel!
    
    /// 内容
    @IBOutlet weak var label_content: UILabel!
    
    /// 确定
    @IBOutlet weak var button_done: YYButton!
    
    var alertTitle: String?
    var textFieldText: String?
    var alertDoneTitle: String?
    var isAutoDismiss: Bool = true
    var isCustom = false
    
    var onDone: onDoneBlock?
    
    init (){
        super.init(nibName: String(describing: YYAlertOKViewController.self), bundle: Bundle.main)
        
        modalTransitionStyle = .crossDissolve
        modalPresentationStyle = .overFullScreen
        
        
    }
    
    class func display(title: String?, text: String?, doneTitle: String?, isAutoDismiss: Bool = true,onDone: @escaping () -> Void) {
        let vc = YYAlertOKViewController()
        vc.alertTitle = title
        vc.textFieldText = text
        vc.alertDoneTitle = doneTitle
        vc.isAutoDismiss = isAutoDismiss
        vc.onDone = onDone
        self.base()?.present(vc, animated: true, completion: nil)
    }
    
    class func display(text: String?, doneTitle: String?,onDone: @escaping () -> Void) {
        let vc = YYAlertOKViewController()
        vc.textFieldText = text
        vc.alertDoneTitle = doneTitle
        vc.onDone = onDone
        vc.isCustom = true
        self.base()?.present(vc, animated: true, completion: nil)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    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_done.setTitle(alertDoneTitle, for: .normal)
        if isCustom{
            button_done.setBackgroundImage(nil, for: .normal)
            button_done.setTitleColor(#colorLiteral(red: 0.9450980392, green: 0.2117647059, blue: 0.1960784314, alpha: 1), for: .normal)
            button_close.isHidden = true
            view_line.isHidden = false
            topConstraint.constant = 12
        }
    }
 
    @IBAction func didPressDoneButton(_ sender: UIButton) {
        if isAutoDismiss {
            dismiss(animated: true) { [unowned self] in
                self.onDone?()
            }
        } else {
            onDone?()
        }
        
    }
    @IBAction func didPressCloseButton(_ sender: UIButton) {
        dismiss(animated: true, completion: nil)
    }
}