Swift UITextField输入到最大限值以后不能删除的解
2019-05-15 本文已影响22人
swift_honor
![](https://img.haomeiwen.com/i8280836/86dca44824fce9b4.png)
话不多说,直接上代码 ,
swift 版本 5.0
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if ((string.count > range.length) &&
(textField.text?.count ?? 0 + string.count - range.length > MAX_LENGHT)) {
return false
}
return true
}