Swift UITextField限制输入字数

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        if range.length == 1 && string.count == 0 {
            return true
        }else if textField.text!.count >= 12 {
            return false
        }
        return true
    }

你可能感兴趣的:(Swift UITextField限制输入字数)