diff --git a/momoIOS/Authentication/Controller/CheckSecurityCodeController.swift b/momoIOS/Authentication/Controller/CheckSecurityCodeController.swift index 8e50a2a..315236c 100644 --- a/momoIOS/Authentication/Controller/CheckSecurityCodeController.swift +++ b/momoIOS/Authentication/Controller/CheckSecurityCodeController.swift @@ -37,6 +37,9 @@ class CheckSecurityCodeController: UIViewController { // MARK: - Lifecyle override func viewDidLoad() { super.viewDidLoad() + + codeField.delegate = self + view.backgroundColor = .white configureUI() codeField.becomeFirstResponder() @@ -80,3 +83,16 @@ class CheckSecurityCodeController: UIViewController { completeButton.addTarget(self, action: #selector(handleCompleteRegistration), for: .touchUpInside) } } + +extension CheckSecurityCodeController: UITextFieldDelegate { + func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { + guard let text = textField.text else { return false } + let maxLength: Int = 12 + + // 최대 글자수 이상을 입력한 이후에는 중간에 다른 글자를 추가할 수 없게끔 작동 + if text.count >= maxLength && range.length == 0 && range.location <= maxLength { + return false + } + return true + } +}