如何检测Siri是否在iOS的textview中编写文本?
我已将文字视图的限制设置为不允许超过50个字符。如果用户从键盘写入,则不允许添加超过50个字符。但是如果我从声音中添加文字,它会超出限制和突破界限。如何检测Siri是否在iOS的textview中编写文本?
所以我不知道为什么它发生了......
任何人都可以帮我吗?
使用该委托,然后再试一次:
func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
let strText = (textView.text as NSString).stringByReplacingCharactersInRange(range, withString: text)
let numberOfChars = strText.characters.count
return numberOfChars < 50;
}
耶得到了解决的支持
if (textView.text.length > 80) {
NSRange range = NSMakeRange(80, textView.text.length - 80);
textView.text = [textView.text stringByReplacingCharactersInRange:range withString:@""];
}
感谢
谢谢answer.i我也在寻找这个问题的答案 –
为什么你提供一个Objective-C解决方案,你的问题是用[swift]标记的? –
你会在哪里应用这个条件。 ?? –
请告诉你如何把限制字符 –
你应该使用文本字段委托来处理这个。 –