在我的应用程序中,我有两个文本字段。 taskTextField和DescTextField。我想将任务文本字段的字符限制为15,并将描述文本字段限制为20.我设法限制了这两个字段,但我不知道如何单独执行它们。这里是我的两个代码:在两个单独的文本域中限制字符Swift 3
let limitLength = 20
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
guard let text = textField.text else { return true }
let newLength = text.characters.count + string.characters.count - range.length
return newLength <= limitLength
}
如何为每个文本字段单独限制任何帮助,将不胜感激。
检查哪个文本字段正在被段“textField”引用到函数中 –