限制中文输入长度
程序员文章站
2022-03-02 12:09:36
...
let toBeString = textView.text
let lang = textView.textInputMode?.primaryLanguage
if lang == "zh-Hans" {
let selectedRange = textView.markedTextRange
if selectedRange == nil && (toBeString?.characters.count)! > 50{
let index = toBeString?.index((toBeString?.startIndex)!, offsetBy: 50)
textView.text = toBeString?.substring(to:index!)
}
}else if (toBeString?.characters.count)! > 50 {
let index = toBeString?.index((toBeString?.startIndex)!, offsetBy: 50)
textView.text = toBeString?.substring(to:index!)
}
上一篇: Js获取CheckBook被选中的值
下一篇: UITextField输入长度限制