- (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 = @""; } }
时间: 2024-10-21 19:53:17