var buttonDelegate: CodeTextFieldDelegate?
func setButtonDelegate(buttonDelegate: CodeTextFieldDelegate) {
self.buttonDelegate = buttonDelegate
}
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
guard let text = textField.text else {
return true
}
let count = text.unicodeScalars.count + string.unicodeScalars.count - range.length
buttonDelegate?.enableButton(enable: count > 0)
let defaultCodeLength = 4
if let length = IsFrontConfig.sms.otp.length.value, let maxCodeLength = Int(length), count > 0 {
return count <= maxCodeLength
} else {
return count <= defaultCodeLength
}
// return true
}
}
protocol CodeTextFieldDelegate {
func enableButton(enable: Bool)
}
Ты не указываешь делегат
Обсуждают сегодня