![UITextView 输入长度限制 UITextView 输入长度限制](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
//还可以输入的长度。
- (void)textViewDidChange:(UITextView *)textView
{
UITextRange *markRange = textView.markedTextRange;
int pos = [textView offsetFromPosition:markRange.start
toPosition:markRange.end];
int nLength = textView.text.length - pos;
if (nLength > 15 && pos == 0)
{
_limit.text = [NSString stringWithFormat:@"%d/%@",15,@"15"];
_nickTextView.text = [textView.text substringToIndex:15];
}
else if(nLength <= 15 && pos == 0)
{
_limit.text = [NSString stringWithFormat:@"%d/%@",[textView.text length],@"15"];
}
}