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

- (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 = @"";
    }
    
}

  

原文地址:https://www.cnblogs.com/yqlog/p/4994177.html