UITextView的字数限制 及 添加自定义PlaceHolder

来源:互联网 发布:青山预算软件 编辑:程序博客网 时间:2024/05/16 12:28
- (void)textViewDidChange:(UITextView *)textView{    NSString *temp=textView.text;   //字数超过限制数量时,进行截取替换    if([[textView text] length] > _limitCharactorNumbers){        textView.text=[temp substringToIndex:_limitCharactorNumbers];    }     //显示剩余字数    _leftNumberLabel.text = [NSString stringWithFormat:@"%u",(_limitCharactorNumbers - textView.text.length)];       // placeHolder实现方法: 自己添加一个UILabel在UITextView左上角    if (textView.text.length == 0) {        _placeHolderLabel.text = _placeHolder;    }else{        _placeHolderLabel.text = @"";    }    }

  

0 0
原创粉丝点击