1.
- (BOOL)textView:(UITextView
- //如果输入超过规定的字数100,就不再让输入
- -
(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text - {
-
if (range.location>=100) -
{ -
return NO; -
} -
else -
{ -
return YES; -
} - }
2.
中来实现。
- -
(BOOL)textField:(UITextField *)textField shouldChangeCharactersIn Range:(NSRange)range replacementString:(NSString *)string - {
-
int remainTextNum_=100; -
//计算剩下多少文字可以输入 -
if(range.location>=100) -
{ -
remainTextNum_=0; -
-
return NO; -
} -
else -
{ -
NSString * nsTextContent=string.text; -
int existTextNum=[nsTextContent length]; -
remainTextNum_=100-existTextNum; -
return YES; -
} -
- }
- //在这个地方计算输入的字数
- -
(void)textViewDidChange:(UITextView *)textView - {
-
NSString * nsTextContent=textView.text; -
int existTextNum=[nsTextContent length]; -
remainTextNum_=100-existTextNum; - }