// // OTPVM.swift // WOKA // // Created by MacBook Pro on 29/04/24. // import UIKit class OTPVM{ weak var vc : OTPVC! func initView(){ let color1 = #colorLiteral(red: 0.144693464, green: 0.1426281333, blue: 0.6686832905, alpha: 1) let color2 = #colorLiteral(red: 0.6901960784, green: 0.2745098039, blue: 0.7568627451, alpha: 1) vc.nextBtn.applyGradient(colors: [color1, color2], startPoint: CGPoint(x: 0, y: 0), endPoint: CGPoint(x: 0.8, y: 0)) vc.nextBtn.roundCorner() self.vc.wokaLogoTopConstriant.constant = CheckPhoneHomeBtnOrNotch.shareInstance.topConstriant() tfMod(textField: [vc.tf1, vc.tf2, vc.tf3, vc.tf4]) if AuthFunc.shareInstance.userType == .adult{ vc.codeSentLabel.text = "Please Get the OTP Sent to Your Email".localized(loc: K.GVar.localized) vc.enterCodeLabel.text = "PLEASE ENTER THE OTP".localized(loc: K.GVar.localized) vc.requestThemLabel.text = "Don’t forget to check your JUNK/SPAM folder".localized(loc: K.GVar.localized) }else{ vc.codeSentLabel.text = "Please Get the Code Sent to Your Parent’s Email".localized(loc: K.GVar.localized) vc.enterCodeLabel.text = "PLEASE ENTER THE CODE".localized(loc: K.GVar.localized) vc.requestThemLabel.text = "Request them for the verfication code to activate your account".localized(loc: K.GVar.localized) } } private func tfMod(textField : [UITextField]){ for i in textField{ i.roundCorner(radius: i.frame.height / 2) i.delegate = vc.self i.textContentType = .oneTimeCode i.addTarget(self, action: #selector(self.textFieldDidChange(textField:)), for: UIControl.Event.editingChanged) } } // MARK: - TextField OTp handling func textFieldDidChange(_ textField: UITextField, otpCode: String) { if textField.textContentType == UITextContentType.oneTimeCode{ //here split the text to your four text fields if otpCode.count == 4, Int(otpCode) != nil { vc.tf1.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 0)]) vc.tf2.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 1)]) vc.tf3.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 2)]) vc.tf4.text = String(otpCode[otpCode.index(otpCode.startIndex, offsetBy: 3)]) // let textFields = [vc.tf1,vc.tf2,vc.tf3,vc.tf4] // for i in 0..