Showing
2 changed files
with
48 additions
and
31 deletions
... | ... | @@ -8,11 +8,11 @@ |
8 | 8 | import UIKit |
9 | 9 | |
10 | 10 | class CodeVerificationView: UIView { |
11 | - | |
12 | 11 | var containerView: UIView = { |
13 | 12 | var obj = UIView() |
14 | 13 | return obj |
15 | 14 | }() |
15 | + | |
16 | 16 | var backButton: UIButton = { |
17 | 17 | var obj = UIButton() |
18 | 18 | obj.setImage(UIImage(named: "BackPointer"), for: .normal) |
... | ... | @@ -22,16 +22,19 @@ class CodeVerificationView: UIView { |
22 | 22 | obj.layer.borderWidth = 1 |
23 | 23 | return obj |
24 | 24 | }() |
25 | + | |
25 | 26 | var logoImage: UIImageView = { |
26 | 27 | var obj = UIImageView() |
27 | 28 | obj.image = UIImage(named: "InterQR") |
28 | 29 | return obj |
29 | 30 | }() |
31 | + | |
30 | 32 | var shieldImage: UIImageView = { |
31 | 33 | var obj = UIImageView() |
32 | 34 | obj.image = UIImage(named: "Lock") |
33 | 35 | return obj |
34 | 36 | }() |
37 | + | |
35 | 38 | var descriptionLabel: UILabel = { |
36 | 39 | var obj = UILabel() |
37 | 40 | obj.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 35) |
... | ... | @@ -101,11 +104,13 @@ class CodeVerificationView: UIView { |
101 | 104 | obj.isHidden = true |
102 | 105 | return obj |
103 | 106 | }() |
107 | + | |
104 | 108 | var verifyButton: UIButton = { |
105 | 109 | var obj = UIButton() |
106 | 110 | obj.setImage(UIImage(named: "RectangleWithShadow"), for: .normal) |
107 | 111 | return obj |
108 | 112 | }() |
113 | + | |
109 | 114 | var verifyLabel: UILabel = { |
110 | 115 | var obj = UILabel() |
111 | 116 | obj.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 16) |
... | ... | @@ -113,11 +118,13 @@ class CodeVerificationView: UIView { |
113 | 118 | obj.text = "Verify" |
114 | 119 | return obj |
115 | 120 | }() |
121 | + | |
116 | 122 | var tickImage: UIImageView = { |
117 | 123 | var obj = UIImageView() |
118 | 124 | obj.image = UIImage(named: "Tick") |
119 | 125 | return obj |
120 | 126 | }() |
127 | + | |
121 | 128 | override init(frame: CGRect) { |
122 | 129 | super.init(frame: frame) |
123 | 130 | layout() |
... | ... | @@ -128,12 +135,13 @@ class CodeVerificationView: UIView { |
128 | 135 | } |
129 | 136 | |
130 | 137 | func layout() { |
131 | - addSubview(textField) | |
132 | - | |
133 | 138 | backgroundColor = .white |
139 | + | |
140 | + addSubview(textField) | |
134 | 141 | addSubview(backButton) |
135 | 142 | addSubview(logoImage) |
136 | 143 | addSubview(shieldImage) |
144 | + | |
137 | 145 | addSubview(containerView) |
138 | 146 | containerView.addSubview(descriptionLabel) |
139 | 147 | containerView.addSubview(firstDigitLabel) |
... | ... | @@ -141,6 +149,7 @@ class CodeVerificationView: UIView { |
141 | 149 | containerView.addSubview(thirdDigitLabel) |
142 | 150 | containerView.addSubview(fourthDigitLabel) |
143 | 151 | containerView.addSubview(errorAlertLabel) |
152 | + | |
144 | 153 | containerView.addSubview(verifyButton) |
145 | 154 | verifyButton.addSubview(verifyLabel) |
146 | 155 | verifyButton.addSubview(tickImage) |
... | ... | @@ -150,40 +159,48 @@ class CodeVerificationView: UIView { |
150 | 159 | $0.leading.equalTo(snp.leading).offset(22) |
151 | 160 | $0.height.width.equalTo(45) |
152 | 161 | } |
162 | + | |
153 | 163 | logoImage.snp.makeConstraints { |
154 | 164 | $0.leading.equalTo(backButton.snp.trailing).offset(20) |
155 | 165 | $0.centerY.equalTo(backButton) |
156 | 166 | } |
167 | + | |
157 | 168 | shieldImage.snp.makeConstraints { |
158 | 169 | $0.top.equalTo(backButton.snp.bottom).offset(25) |
159 | 170 | $0.right.equalTo(snp.right).offset(-101) |
160 | 171 | } |
172 | + | |
161 | 173 | containerView.snp.makeConstraints { |
162 | 174 | $0.top.equalTo(backButton.snp.bottom).offset(227) |
163 | 175 | $0.leading.trailing.equalToSuperview() |
164 | 176 | $0.height.equalTo(300) |
165 | 177 | } |
178 | + | |
166 | 179 | descriptionLabel.snp.makeConstraints { |
167 | 180 | $0.leading.equalTo(containerView.snp.leading).offset(20) |
168 | 181 | $0.top.equalTo(containerView.snp.top) |
169 | 182 | } |
183 | + | |
170 | 184 | firstDigitLabel.snp.makeConstraints { |
171 | 185 | $0.leading.equalTo(containerView.snp.leading).offset(25) |
172 | 186 | $0.top.equalTo(descriptionLabel.snp.bottom).offset(28) |
173 | 187 | $0.height.equalTo(55) |
174 | 188 | } |
189 | + | |
175 | 190 | secondDigitLabel.snp.makeConstraints { |
176 | 191 | $0.leading.equalTo(firstDigitLabel.snp.trailing).offset(12) |
177 | 192 | $0.centerY.equalTo(firstDigitLabel) |
178 | 193 | $0.width.equalTo(firstDigitLabel.snp.width) |
179 | 194 | $0.height.equalTo(55) |
180 | 195 | } |
196 | + | |
181 | 197 | thirdDigitLabel.snp.makeConstraints { |
182 | 198 | $0.leading.equalTo(secondDigitLabel.snp.trailing).offset(12) |
183 | 199 | $0.centerY.equalTo(firstDigitLabel) |
184 | 200 | $0.width.equalTo(firstDigitLabel.snp.width) |
185 | 201 | $0.height.equalTo(55) |
186 | 202 | } |
203 | + | |
187 | 204 | fourthDigitLabel.snp.makeConstraints { |
188 | 205 | $0.leading.equalTo(thirdDigitLabel.snp.trailing).offset(12) |
189 | 206 | $0.centerY.equalTo(firstDigitLabel) |
... | ... | @@ -191,18 +208,22 @@ class CodeVerificationView: UIView { |
191 | 208 | $0.width.equalTo(firstDigitLabel.snp.width) |
192 | 209 | $0.height.equalTo(55) |
193 | 210 | } |
211 | + | |
194 | 212 | errorAlertLabel.snp.makeConstraints { |
195 | 213 | $0.top.equalTo(firstDigitLabel.snp.bottom).offset(8) |
196 | 214 | $0.leading.equalTo(firstDigitLabel.snp.leading) |
197 | 215 | } |
216 | + | |
198 | 217 | verifyButton.snp.makeConstraints { |
199 | 218 | $0.top.equalTo(firstDigitLabel.snp.bottom).offset(67) |
200 | 219 | $0.left.right.equalToSuperview() |
201 | 220 | } |
221 | + | |
202 | 222 | verifyLabel.snp.makeConstraints { |
203 | 223 | $0.left.equalToSuperview().offset(49) |
204 | 224 | $0.top.equalToSuperview().offset(22) |
205 | 225 | } |
226 | + | |
206 | 227 | tickImage.snp.makeConstraints { |
207 | 228 | $0.right.equalToSuperview().offset(-47) |
208 | 229 | $0.centerY.equalTo(verifyLabel) | ... | ... |
InterQR-Internship/Modules/OneTimePasswordScreen/ViewController/CodeVerificationViewController.swift
... | ... | @@ -8,9 +8,10 @@ |
8 | 8 | import UIKit |
9 | 9 | |
10 | 10 | class CodeVerificationViewController: UIViewController { |
11 | - | |
12 | 11 | var otp: String = "" |
12 | + | |
13 | 13 | var isKeyboardAppear = false |
14 | + | |
14 | 15 | private let mainView = CodeVerificationView() |
15 | 16 | |
16 | 17 | override func loadView() { |
... | ... | @@ -23,8 +24,10 @@ class CodeVerificationViewController: UIViewController { |
23 | 24 | |
24 | 25 | private func initViewController() { |
25 | 26 | mainView.textField.delegate = self |
27 | + | |
26 | 28 | mainView.backButton.addTarget(self, action: #selector(didDismissVC), for: .touchUpInside) |
27 | 29 | mainView.verifyButton.addTarget(self, action: #selector(didVerifyCode), for: .touchUpInside) |
30 | + | |
28 | 31 | NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil) |
29 | 32 | NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) |
30 | 33 | } |
... | ... | @@ -34,32 +37,32 @@ class CodeVerificationViewController: UIViewController { |
34 | 37 | NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil) |
35 | 38 | } |
36 | 39 | } |
37 | - | |
40 | +//MARK: - Targets | |
38 | 41 | extension CodeVerificationViewController { |
39 | 42 | |
40 | - @objc func didDismissVC() { | |
43 | + @objc private func didDismissVC() { | |
41 | 44 | navigationController?.popViewController(animated: true) |
42 | 45 | } |
43 | 46 | |
44 | - @objc func didVerifyCode() { | |
47 | + @objc private func didVerifyCode() { | |
45 | 48 | if mainView.fourthDigitLabel.text == nil { |
46 | 49 | let alert = UIAlertController(title: "❌❌❌", message: "Some fields are empty, please fill in all", preferredStyle: .alert) |
47 | 50 | let _: Void = alert.addAction(UIAlertAction(title: "Close", style: .cancel, handler: nil)) |
48 | 51 | present(alert, animated: true, completion: nil) |
49 | 52 | |
50 | 53 | } else { |
51 | - mainView.firstDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1) | |
52 | - mainView.firstDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1) | |
53 | - | |
54 | - mainView.secondDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1) | |
55 | - mainView.secondDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1) | |
56 | - | |
57 | - mainView.thirdDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1) | |
58 | - mainView.thirdDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1) | |
59 | - | |
60 | - mainView.fourthDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1) | |
61 | - mainView.fourthDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1) | |
62 | - mainView.errorAlertLabel.isHidden = false | |
54 | + mainView.firstDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1) | |
55 | + mainView.firstDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1) | |
56 | + | |
57 | + mainView.secondDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1) | |
58 | + mainView.secondDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1) | |
59 | + | |
60 | + mainView.thirdDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1) | |
61 | + mainView.thirdDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1) | |
62 | + | |
63 | + mainView.fourthDigitLabel.backgroundColor = UIColor(red: 1, green: 0.929, blue: 0.941, alpha: 1) | |
64 | + mainView.fourthDigitLabel.textColor = UIColor(red: 1, green: 0, blue: 0.18, alpha: 1) | |
65 | + mainView.errorAlertLabel.isHidden = false | |
63 | 66 | |
64 | 67 | DispatchQueue.main.asyncAfter(deadline: .now() + 3) { |
65 | 68 | let vc = HomeViewController() |
... | ... | @@ -69,12 +72,10 @@ extension CodeVerificationViewController { |
69 | 72 | } |
70 | 73 | } |
71 | 74 | |
72 | - | |
73 | - @objc func keyboardWillShow(notification: NSNotification) { | |
75 | + @objc private func keyboardWillShow(notification: NSNotification) { | |
74 | 76 | let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double |
75 | - | |
77 | + | |
76 | 78 | if !isKeyboardAppear { |
77 | - | |
78 | 79 | UIView.animate(withDuration: duration ?? 0) { |
79 | 80 | self.mainView.containerView.snp.updateConstraints { make in |
80 | 81 | make.top.equalTo(self.mainView.backButton.snp.bottom).offset(97) |
... | ... | @@ -84,16 +85,14 @@ extension CodeVerificationViewController { |
84 | 85 | } |
85 | 86 | self.mainView.layoutIfNeeded() |
86 | 87 | } |
87 | - | |
88 | 88 | isKeyboardAppear = true |
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
92 | - @objc func keyboardWillHide(notification: NSNotification) { | |
92 | + @objc private func keyboardWillHide(notification: NSNotification) { | |
93 | 93 | let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double |
94 | - | |
94 | + | |
95 | 95 | if isKeyboardAppear { |
96 | - | |
97 | 96 | UIView.animate(withDuration: duration ?? 0) { |
98 | 97 | self.mainView.containerView.snp.updateConstraints { make in |
99 | 98 | make.top.equalTo(self.mainView.backButton.snp.bottom).offset(227) |
... | ... | @@ -103,13 +102,12 @@ extension CodeVerificationViewController { |
103 | 102 | } |
104 | 103 | self.mainView.layoutIfNeeded() |
105 | 104 | } |
106 | - | |
107 | 105 | isKeyboardAppear = false |
108 | 106 | } |
109 | 107 | } |
110 | - | |
111 | 108 | } |
112 | 109 | |
110 | +//MARK: - TextField delegate | |
113 | 111 | extension CodeVerificationViewController: UITextFieldDelegate { |
114 | 112 | |
115 | 113 | func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { |
... | ... | @@ -130,8 +128,6 @@ extension CodeVerificationViewController: UITextFieldDelegate { |
130 | 128 | mainView.textField.endEditing(true) |
131 | 129 | } |
132 | 130 | } |
133 | - | |
134 | 131 | return true |
135 | 132 | } |
136 | - | |
137 | 133 | } | ... | ... |
Please
register
or
login
to post a comment