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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
//
// ZCAlertView.swift
// zc
//
// Created by wyp on 2020/11/4.
// Copyright © 2020 wyp. All rights reserved.
//
import UIKit
class ZCAlertView: UIView {
typealias clickAlertClosure = (_ index: Int) -> Void
var clickClosure: clickAlertClosure!
let bgView = UIView() //白色框
// let bgImageView = UIImageView()
let textField: UITextField = UITextField()
// let countLabel = UILabel()
private lazy var titleLabel: UILabel = {
let label = UILabel()
// label.text = title
label.font = RegularFont(16)
label.textColor = ZCTextColor
label.textAlignment = .center
label.numberOfLines = 0
return label
}()
private lazy var sureBtn: UIButton = {
let button = UIButton()
button.addTarget(self, action: #selector(clickBtnAction(_:)), for: .touchUpInside)
button.setColor(radio: 15, color: UIColor.rgbColorFromHex(0x3D5A80), borderColor: .clear, textColor: .white, text: LocString("确定"))
button.titleLabel?.font = RegularFont(14)
button.tag = 1
return button
}()
private lazy var cancelBtn: UIButton = {
let button = UIButton()
button.addTarget(self, action: #selector(clickBtnAction(_:)), for: .touchUpInside)
button.setColor(radio: 15, color: .white, borderColor: UIColor.rgbColorFromHex(0x999999), textColor: UIColor.rgbColorFromHex(0x999999), text: LocString("取消"))
button.titleLabel?.font = RegularFont(14)
button.tag = 2
return button
}()
init(title: String, sureText: String = LocString("确定"), cancelText: String = LocString("取消")) {
super.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT))
createView(title: title, sureText: sureText, cancelText: cancelText)
}
func createView(title: String, sureText: String, cancelText: 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
addSubview(bgView)
bgView.addSubview(titleLabel)
bgView.addSubview(sureBtn)
bgView.addSubview(cancelBtn)
bgView.snp.makeConstraints { (make) in
make.centerX.equalToSuperview()
make.centerY.equalToSuperview()
make.left.equalToSuperview().offset(40)
make.right.equalToSuperview().offset(-40)
make.bottom.equalTo(sureBtn.snp.bottom).offset(20)
// make.height.equalTo(120)
}
titleLabel.snp.makeConstraints { (make) in
make.left.equalToSuperview().offset(25)
make.right.equalToSuperview().offset(-25)
make.top.equalToSuperview().offset(20)
}
sureBtn.snp.makeConstraints { (make) in
make.centerX.equalToSuperview().multipliedBy(1.4)
make.height.equalTo(30)
make.width.equalTo(80)
make.top.equalTo(titleLabel.snp.bottom).offset(30)
}
cancelBtn.snp.makeConstraints { (make) in
make.centerX.equalToSuperview().multipliedBy(0.6)
make.centerY.equalTo(sureBtn)
make.width.equalTo(sureBtn.snp.width)
make.height.equalTo(sureBtn.snp.height)
}
sureBtn.setTitle(sureText, for: .normal)
cancelBtn.setTitle(cancelText, for: .normal)
}
// func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
// let textFieldText = textField.text ?? ""
// let existedLength : Int = textFieldText.count
// let selectedLength : Int = range.length
// let replaceLength : Int = string.count
// let pointLength : Int = existedLength - selectedLength + replaceLength
//// print(selectedLength)
// //超过16位 就不能在输入了
// if (pointLength > 16) {
// return false
// } else {
// return true
// }
// }
//
//
//
@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
}
*/
}
|