對輸入框有漢字輸入而且有長度限制時候的處理

一、要對長度進行限制spa

二、當拼音正在輸入,漢字是在高亮的模式下的時候,不該該進行限制,應該容許用戶繼續輸入。當輸入完成後再對其輸入的內容進行截取。string

因而代碼以下:it

- (void)textViewDidChange:(UITextView *)textViewtable

{im

 //獲取高亮的內容tab

    UITextRange* textRange = textView.markedTextRange;return

  //有高亮的內容直接返回void

    if(textRange)ab

    {

        return;

    }

    

    NSString *strText = textView.text;

    if ([strText length] > self.limitCount)

    {

        NSMutableString *strTmp = [NSMutableString stringWithString:[strText substringToIndex:self.limitCount]];

        textView.text = strTmp;

    }

}

相關文章
相關標籤/搜索