CNLiveLoginViewController.swift
11.4 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
//
// CNLiveLoginViewController.swift
// metaCode
//
// Created by open on 2023/6/5.
//
import Foundation
import UIKit
import SnapKit
class CNLiveLoginViewController : CNLiveBaseViewController, UITextViewDelegate {
lazy var headerView : UIImageView = {
let headerView = UIImageView()
headerView.backgroundColor = .white
headerView.contentMode = .scaleAspectFit
headerView.image = UIImage(named: "Login_page_header_icon")
return headerView
}()
lazy var areaButton : UIButton = {
let areaButton = UIButton(type: .custom)
areaButton.backgroundColor = .white
areaButton.setTitle("+86", for: .normal)
areaButton.setTitle("+86", for: .highlighted)
areaButton.titleLabel?.font = BoldFont_16_Fit
areaButton.setTitleColor(HexColor("#333333"), for: .normal)
areaButton.setTitleColor(HexColor("#333333"), for: .highlighted)
areaButton.addTarget(self, action: #selector(changeCityNumberMothod), for: .touchUpInside)
return areaButton
}()
var phoneText = UITextField()//手机号
var veriText = UITextField()//验证码
var timeOut = 30//多少秒计时器
override func viewDidLoad() {
super.viewDidLoad()
//添加主视图
self.view.addSubview(self.headerView)
self.headerView.snp.makeConstraints { make in
make.centerX.equalTo(self.view)
make.top.left.right.equalTo(self.view)
make.height.equalTo(250.0)
}
self.setupPhoneView()
self.setupVeriCodeView()
self.setupLoginButtonView()
}
deinit {
print("已经销毁了")
}
func setupPhoneView() {
let phoneV = UIView.init()
phoneV.backgroundColor = .white
self.view.addSubview(phoneV)
phoneV.snp.makeConstraints { make in
make.left.right.equalTo(self.view)
make.top.equalTo(self.headerView.snp.bottom).offset(10)
make.height.equalTo(50)
}
phoneV.addSubview(areaButton)
areaButton.snp.makeConstraints { make in
make.centerY.equalTo(phoneV)
make.left.equalTo(phoneV.left).offset(40)
make.width.lessThanOrEqualTo(45)
}
let v_line = UILabel.init()
v_line.backgroundColor = HexColor("#EBEBEB")
phoneV.addSubview(v_line)
v_line.snp.makeConstraints { make in
make.centerY.equalTo(phoneV)
make.left.equalTo(areaButton.snp.right).offset(10)
make.width.equalTo(1)
make.height.equalTo(areaButton.snp.height).multipliedBy(0.35)
}
let h_line = UILabel.init()
h_line.backgroundColor = HexColor("#EBEBEB")
phoneV.addSubview(h_line)
h_line.snp.makeConstraints { make in
make.left.equalTo(phoneV.left).offset(40)
make.right.equalTo(phoneV.right).offset(-40)
make.height.equalTo(v_line.snp.width)
make.bottom.equalTo(phoneV.snp.bottom).offset(-1)
}
self.phoneText = UITextField.init()
self.phoneText.backgroundColor = .white
self.phoneText.placeholder = "输入手机号"
self.phoneText.font = BoldFont_16_Fit
self.phoneText.keyboardType = .numberPad
self.phoneText.clearButtonMode = .whileEditing
phoneV.addSubview(self.phoneText)
self.phoneText.snp.makeConstraints { make in
make.centerY.equalTo(phoneV)
make.left.equalTo(areaButton.snp.right).offset(21)
make.height.equalTo(areaButton.snp.height)
make.right.equalTo(phoneV.right).offset(-40)
}
}
func setupVeriCodeView() {
let verView = UIView.init()
verView.backgroundColor = .white
self.view.addSubview(verView)
verView.snp.makeConstraints { make in
make.left.right.equalTo(self.view)
make.top.equalTo(self.headerView.snp.bottom).offset(70)
make.height.equalTo(50)
}
let h_line = UILabel.init()
h_line.backgroundColor = HexColor("#EBEBEB")
verView.addSubview(h_line)
h_line.snp.makeConstraints { make in
make.left.equalTo(verView.left).offset(40)
make.right.equalTo(verView.right).offset(-40)
make.height.equalTo(1)
make.bottom.equalTo(verView.snp.bottom).offset(-1)
}
let codeButton = UIButton(type: .custom)
codeButton.backgroundColor = .white
codeButton.setTitle("获取验证码", for: .normal)
codeButton.setTitle("获取验证码", for: .highlighted)
codeButton.titleLabel?.font = Font_16_Fit
codeButton.setTitleColor(HexColor("#0066FE"), for: .normal)
codeButton.setTitleColor(HexColor("#0066FE"), for: .highlighted)
codeButton.addTarget(self, action: #selector(sendVerifiCodeMothod), for: .touchUpInside)
verView.addSubview(codeButton)
codeButton.snp.makeConstraints { make in
make.centerY.equalTo(verView)
make.right.equalTo(verView.snp.right).offset(-40)
make.width.lessThanOrEqualTo(100)
}
self.veriText = UITextField.init()
self.veriText.backgroundColor = .white
self.veriText.placeholder = "输入验证码"
self.veriText.font = BoldFont_16_Fit
self.veriText.keyboardType = .numberPad
self.veriText.clearButtonMode = .whileEditing
verView.addSubview(self.veriText)
self.veriText.snp.makeConstraints { make in
make.centerY.equalTo(verView)
make.right.equalTo(codeButton.snp.left).offset(-20)
make.height.equalTo(codeButton.snp.height)
make.left.equalTo(verView.snp.left).offset(40)
}
let tipLabel = UILabel.init()
tipLabel.text = "未注册的手机号验证后自动为您创建元码账户"
tipLabel.textColor = HexColor("#464646")
tipLabel.textAlignment = .left
tipLabel.font = Font_11_Fit
self.view.addSubview(tipLabel)
tipLabel.snp.makeConstraints { make in
make.centerX.equalTo(self.view)
make.left.right.equalTo(self.view).offset(40)
make.top.equalTo(verView.snp.bottom).offset(10)
}
}
func setupLoginButtonView() {
let selectButton = UIButton(type: .custom)
selectButton.backgroundColor = .white
selectButton.setImage(UIImage(named: "Login_body_choose_btn_nomal"), for: .normal)
selectButton.setImage(UIImage(named: "Login_body_choose_btn_nomal"), for: .highlighted)
selectButton.setImage(UIImage(named: "Login_body_choose_btn_select"), for: .selected)
selectButton.contentMode = .scaleAspectFill
selectButton.addTarget(self, action: #selector(changeSelectBtnMothod), for: .touchUpInside)
view.addSubview(selectButton)
selectButton.snp.makeConstraints { make in
make.bottom.equalTo(view.snp.bottom).offset(-50)
make.left.equalTo(view.snp.left).offset(25)
make.size.equalTo(15)
}
let attributedString = NSMutableAttributedString(string: "我已阅读并同意《APP用户服务协议》《个人信息保护政策》",
attributes: [.foregroundColor: HexColor("#999999") as Any, .font: Font_10])
let p_Range = NSRange(attributedString.string.range(of: "《APP用户服务协议》")!, in: attributedString.string)
attributedString.addAttribute(.link, value: "delegate://", range: p_Range)
let i_Range = NSRange(attributedString.string.range(of: "《个人信息保护政策》")!, in: attributedString.string)
attributedString.addAttribute(.link, value: "info://", range: i_Range)
let textView: UITextView = UITextView.init()
textView.backgroundColor = .white
textView.isEditable = false
textView.isScrollEnabled = false
textView.delegate = self
textView.attributedText = attributedString
view.addSubview(textView)
textView.snp.makeConstraints { make in
make.centerY.equalTo(selectButton)
make.left.equalTo(selectButton.snp.right)
make.right.equalTo(view.snp.right).offset(-25)
}
let loginButton = UIButton(type: .custom)
loginButton.setTitle("登 陆", for: .normal)
loginButton.setTitleColor(.white, for: .normal)
loginButton.titleLabel?.font = BoldFont_16_Fit
loginButton.layer.cornerRadius = 20
loginButton.layer.masksToBounds = true
view.addSubview(loginButton)
loginButton.snp.makeConstraints { make in
make.centerX.equalTo(view)
make.bottom.equalTo(textView.snp.top).offset(-10)
make.left.equalTo(40)
make.right.equalTo(-40)
make.height.equalTo(40)
}
loginButton.setGradient(colors: [UIColor(red: 103/255.0, green: 197/255.0, blue: 255/255.0, alpha: 1),UIColor(red: 96/255.0, green: 154/255.0, blue: 255/255.0, alpha: 1)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
}
}
extension CNLiveLoginViewController {
@objc func changeCityNumberMothod(sender : UIButton) {
CNLiveLoginPickerView.showSelectView { [self] text in
areaButton.setTitle("+\(text)", for: .normal)
areaButton.setTitle("+\(text)", for: .highlighted)
}
}
@objc func sendVerifiCodeMothod(sender : UIButton) {
var timeOut = self.timeOut
let queue: DispatchQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default)
let _timer: DispatchSource = DispatchSource.makeTimerSource(flags: [], queue: queue) as! DispatchSource
_timer.schedule(wallDeadline: DispatchWallTime.now(), repeating: .seconds(1))
//一秒执行
_timer.setEventHandler(handler: { () -> Void in
if timeOut <= 0 {
_timer.cancel()
DispatchQueue.main.sync(execute: { () -> Void in
sender.setTitle("获取验证码", for: .normal)
sender.isEnabled = true
})
} else {
let seconds = timeOut
DispatchQueue.main.sync(execute: {() -> Void in
let str = String(describing: seconds)
sender.setTitle("\(str)s重新获取", for: .normal)
sender.isEnabled = false
})
timeOut -= 1
}
})
_timer.resume()
}
@objc func changeSelectBtnMothod(sender : UIButton) {
sender.isSelected = !sender.isSelected
}
@objc func sendLoginActionMothod(sender : UIButton) {
}
@objc func pushAgreeActionMothod() {
}
@objc func pushInfoActionMothod() {
}
}
extension CNLiveLoginViewController {
func textView(_ textView: UITextView, shouldInteractWith textAttachment: NSTextAttachment, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
return false
}
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
if URL.absoluteString == "delegate://" {
pushAgreeActionMothod()
return false
}else {
pushInfoActionMothod()
return false
}
}
}