记录自己用到的方法
textField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: UIControl.Event.editingChanged)
@objc func textFieldDidChange(_ textField: UITextField) {
// 系统自带拼音输入法bug
if let _ = textField.markedTextRange {
} else {
if let text = textField.text {
if text.count > kNickNameMaxCount {
textField.text = text.lx_subString(to: kNickNameMaxCount)
}
numLabel.text = "\(textField.text?.count ?? 0)/\(kNickNameMaxCount)"
}
}
}
网友评论