【发布时间】:2016-02-19 14:20:51
【问题描述】:
我有一个 UITextField,我想将长度限制为 4 个字符,这是它的代码:
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
guard let text = acRegTextField.text else { return true }
let newLength = text.utf16.count + string.utf16.count - range.length
return newLength <= 4 // Bool
}
问题是,使用此代码,当 acRegTextField 中包含 4 个字符时,我的其他文本框会停止。
我真的不明白...任何帮助将不胜感激
谢谢
【问题讨论】:
标签: ios swift uitextfield swift2