Board logo

标题: 限制中文输入长度 [打印本页]

作者: look_w    时间: 2019-2-19 17:10     标题: 限制中文输入长度

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!)
}




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0