美文网首页
textView字数限制

textView字数限制

作者: zmjchuan | 来源:发表于2018-05-11 16:47 被阅读11次
    //正在改变
    - (void)textViewDidChange:(UITextView *)textView
    {
        NSLog(@"%@", textView.text);
        //实时显示字数
        self.strlength.text = [NSString stringWithFormat:@"%lu/120", (unsigned long)textView.text.length];
        
        //字数限制操作
        if (textView.text.length >= 120) {
            
            textView.text = [textView.text substringToIndex:120];
            self.strlength.text = @"120/120";
            SHOW_ALERT(@"最多只能输入120字");
        } else {
        }
       
    }
    
    #pragma mark  - lazy
    - (TextViewPlaceHolder *)textView
    {
        if (!_textView) {
            _textView = [[TextViewPlaceHolder alloc]init];
            _textView.delegate = self;
            _textView.placeholder = @"请发表您的评论...";
            _textView.font = SFONT(ChangeSizeNOPlus(16));
        }
        return _textView;
    }
    
    - (UILabel *)strlength
    {
        if (!_strlength) {
            _strlength = [[UILabel alloc]init];
            _strlength.font = SFONT(ChangeSizeNOPlus(13));
            _strlength.textColor = Text_Color;
            _strlength.text = @"0/120";
        }
        return _strlength;
    }
    
    QQ20180511-164908-HD.gif

    相关文章

      网友评论

          本文标题:textView字数限制

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