- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
NSInteger maxLength = 200;
NSString *appendStr = [textView.text stringByReplacingCharactersInRange:range withString:text];
NSInteger restNum = maxLength -[appendStr length];
//
if(restNum >= 0){
return YES;
}
else{
NSRange rg = {0,[text length]+restNum};
if (rg.length>0) {
NSString *s = [text substringWithRange:rg];
[textView setText:[textView.text stringByReplacingCharactersInRange:range withString:s]];
}
[self textViewDidChange:textView];
return NO;
}
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)text
{
NSInteger maxLength = 100;
NSString *appendStr = [textField.text stringByReplacingCharactersInRange:range withString:text];
NSInteger restNum = maxLength -[appendStr length];
if(restNum >= 0){
return YES;
}
else{
NSRange rg = {0,[text length]+restNum};
if (rg.length>0) {
NSString *s = [text substringWithRange:rg];
[textField setText:[textField.text stringByReplacingCharactersInRange:range withString:s]];
}
[self TextFieldChangeAction:nil];
return NO;
}
}
阅读(872) | 评论(0) | 转发(0) |