swift textView字数限制,textView点击完成隐藏键盘
效果圖:
?
//MARK: -UITextViewDelegate
func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
? ? ? ? if (text == "\n") { ?//?textView點擊完成隱藏鍵盤
? ? ? ? ? ? textView.resignFirstResponder()?
? ? ? ? ? ? return false
? ? ? ? }
? ? ? ? //字數限制,在這里我的處理是給了一個簡單的提示,你也可以在這兒處理其他的顯示方式。
? ? ? ? if range.location >= 30 {
? ? ? ? ? ? SVProgressHUD.showErrorWithStatus("超過字數限制。", maskType: SVProgressHUDMaskType.Clear)
? ? ? ? ? ? return false
? ? ? ? }
? ? ? ? return true
? ? }
//swift2.3寫的,3.0的話只是語法的一點改動而已。
?
轉載于:https://www.cnblogs.com/caodedi-88/p/6269616.html
總結
以上是生活随笔為你收集整理的swift textView字数限制,textView点击完成隐藏键盘的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: BZOJ 2668: [cqoi2012
- 下一篇: delphi实现两个目录路径的链接