CNLiveMineNickViewController.swift
4.53 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
//
// CNLiveMineNickViewController.swift
// metaCode
//
// Created by open on 2023/6/9.
//
import Foundation
class CNLiveMineNickViewController: CNLiveBaseViewController, UITextFieldDelegate {
lazy var saveButton: UIButton = {
let saveButton = UIButton.init(type: .custom)
saveButton.frame = CGRect(x: KSreenWidth - 70, y: (get_system_nav_height() - (get_system_statusBar_height() + 25))/2 + get_system_statusBar_height(), width: 60, height: 25)
saveButton.setTitle("保存", for: .normal)
saveButton.titleLabel?.font = Font_15
saveButton.setTitleColor(.white, for: .normal)
saveButton.backgroundColor = HexColor("#EBEBEB")
saveButton.layer.masksToBounds = true
saveButton.layer.cornerRadius = 5
saveButton.addTarget(self, action: #selector(clickSaveAction), for: .touchUpInside)
return saveButton
}()
lazy var mainView: UIView = {
let mainView = UIView.init()
mainView.backgroundColor = .white
mainView.layer.cornerRadius = 8
mainView.layer.masksToBounds = true
return mainView
}()
lazy var nickField: UITextField = {
let nickFielld = UITextField.init()
nickFielld.backgroundColor = .white
nickFielld.placeholder = "输入昵称"
nickFielld.font = BoldFont_16_Fit
nickFielld.delegate = self
nickFielld.text = UserInfoManager.shared.userInfo.nickName
nickFielld.keyboardType = .default
nickFielld.clearButtonMode = .whileEditing
return nickFielld
}()
override func viewDidLoad() {
super.viewDidLoad()
titleName = "更改昵称"
navigationBarHidden = false
topNavView.addSubview(saveButton)
view.addSubview(mainView)
mainView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.left.equalToSuperview().offset(10)
make.top.equalToSuperview().offset(get_system_nav_height()+10)
make.right.equalToSuperview().offset(-10)
make.height.equalTo(50)
}
mainView.addSubview(nickField)
nickField.snp.makeConstraints { make in
make.centerX.equalTo(mainView)
make.top.equalToSuperview().offset(5)
make.left.equalToSuperview().offset(10)
make.right.equalToSuperview().offset(-10)
make.bottom.equalToSuperview().offset(-5)
}
setupWithSendBtnStatue(statue: true)
}
private func setupWithSendBtnStatue(statue: Bool) {
if statue {
saveButton.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))
} else {
saveButton.setGradient(colors: [UIColor(red: 235/255.0, green: 235/255.0, blue: 235/255.0, alpha: 1)], startPoint: CGPoint(x: 0, y: 1), endPoint: CGPoint(x: 1, y: 0))
}
var color: UIColor = UIColor.white
if !statue {
color = HexColor("#999999")!
}
saveButton.isUserInteractionEnabled = statue
saveButton.setTitleColor(color, for: .normal)
}
@objc func clickSaveAction() {
CNLiveMineViewModel.requestUpdateUserInfoAction(type: .nickName, value: nickField.text ?? "", resultBlock: { [self] in
let userInfo = UserInfoManager.shared.userInfo
userInfo.nickName = nickField.text ?? ""
UserInfoManager.cacheUserInfo(userInfo: userInfo)
})
}
func textFieldDidBeginEditing(_ textField: UITextField) {
if textField == nickField {
mainView.layer.borderColor = HexColor("#0066FE")?.cgColor
mainView.layer.borderWidth = 1
setupWithSendBtnStatue(statue: true)
}
}
func textFieldDidEndEditing(_ textField: UITextField) {
if textField == nickField && textField.text?.count == 0 {
mainView.layer.borderColor = UIColor.white.cgColor
mainView.layer.borderWidth = 1
setupWithSendBtnStatue(statue: false)
}
}
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if textField.returnKeyType == .done {
if string == "\n" {
textField.resignFirstResponder()
}
return true
}
return true
}
}