Blame view

HDFwear/Setting/VIew/FirmwareRemindView.swift 3.84 KB
f2cf74c7   yangbin   1.0.20(4)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  //
  //  FirmwareRemindView.swift
  //  HDFwear
  //
  //  Created by yangbin on 2022/3/16.
  //
  
  import UIKit
  import SnapKit
  
  class FirmwareRemindView: UIView {
  
      typealias clickAlertClosure = (_ index: Int) -> Void
      var clickClosure: clickAlertClosure!
      
      let bgView = UIView() //白色框
  
  
      private lazy var titleLabel: UILabel = {
          let label = UILabel()
          label.font = RegularFont(15)
          label.textColor = .black
          label.numberOfLines = 0
          return label
      }()
      
      private lazy var detailLabel: UILabel = {
          let label = UILabel()
          label.font = RegularFont(13)
          label.textColor = .black
          label.numberOfLines = 0
          return label
      }()
      
      private lazy var sureBtn: UIButton = {
          let button = UIButton()
          button.addTarget(self, action: #selector(clickBtnAction(_:)), for: .touchUpInside)
          button.setTitleColor(TintColor, for: .normal)
          button.titleLabel?.font = BoldFont(15)
          button.tag = 1
          return button
      }()
      
      init(title: String, detail: String, sureText: String = LocString("确定")) {
          super.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT))
          createView(title: title, detail: detail, sureText: sureText)
      }
      
      func createView(title: String, detail: String, sureText: String) {
  //        self.frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT)
          self.backgroundColor = UIColor.black.withAlphaComponent(0.7)
          
          bgView.layer.cornerRadius = 10
          bgView.clipsToBounds = true
          bgView.backgroundColor = .white
          
  
          titleLabel.text = title
          detailLabel.text = detail
          addSubview(bgView)
          bgView.addSubview(titleLabel)
          bgView.addSubview(detailLabel)
          bgView.addSubview(sureBtn)
          
          bgView.snp.makeConstraints { (make) in
              make.centerY.equalToSuperview().multipliedBy(0.92)
              make.left.equalToSuperview().offset(40)
              make.right.equalToSuperview().offset(-40)
              make.bottom.equalTo(sureBtn.snp.bottom).offset(15)
          }
          
          
          titleLabel.snp.makeConstraints { (make) in
              make.left.equalToSuperview().offset(16)
              make.right.equalToSuperview().offset(-16)
              make.top.equalToSuperview().offset(12)
          }
          
          detailLabel.snp.makeConstraints { (make) in
              make.left.equalToSuperview().offset(16)
              make.right.equalToSuperview().offset(-16)
              make.top.equalTo(titleLabel.snp.bottom).offset(10)
          }
  
  
          sureBtn.snp.makeConstraints { (make) in
              make.right.equalToSuperview().offset(-16)
              make.top.equalTo(detailLabel.snp.bottom).offset(25)
          }
          
          
          sureBtn.setTitle(sureText, for: .normal)
  
      }
      
      
  
  
      
      
      @objc func clickBtnAction(_ sender: UIButton) {
          if (clickClosure != nil) {
              clickClosure!(sender.tag)
          }
          dismiss()
      }
      
      func show() {
          let wind = KeyWindow
          self.alpha = 0
          
          wind.addSubview(self)
          UIView.animate(withDuration: 0.25, animations: { () -> Void in
              self.alpha = 1
          })
      }
      
      @objc func dismiss() {
          UIView.animate(withDuration: 0.25, animations: { () -> Void in
              self.alpha = 0
          }, completion: { (finish) -> Void in
              if finish {
                  self.removeFromSuperview()
              }
          })
      }
      
      
      
      required init?(coder aDecoder: NSCoder) {
          fatalError("init(coder:) has not been implemented")
      }
      
  
      /*
      // Only override draw() if you perform custom drawing.
      // An empty implementation adversely affects performance during animation.
      override func draw(_ rect: CGRect) {
          // Drawing code
      }
      */
  
  }