UITextView 输入长度限制

//还可以输入的长度。
- (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"];
    }
}

  

posted @ 2014-10-24 13:27  菜鸟程序猿  阅读(471)  评论(0编辑  收藏  举报