美文网首页
UITextView限制字数不超过50

UITextView限制字数不超过50

作者: CN_HarrySun | 来源:发表于2018-08-10 14:10 被阅读9次

// 问题描述限制50个字

设置delegate

遵循UITextViewDelegate

代码限制字数不超过50

func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
        
        if text == "" {
            return true
        }
        if textView.text.count > 49 {
            return false
        }
        return true
    }

相关文章

网友评论

      本文标题:UITextView限制字数不超过50

      本文链接:https://www.haomeiwen.com/subject/tppjvftx.html