I need to limit the number of characters that a user could enter in a text view. Im limiting this to 500 characters. Below is my code,
- (void)textViewDidChange:(UITextView *)textView{
NSInteger restrictedLength=500;
NSString *temp=textView.text;
NSLog(@"hekk %ld",[[textView text]length]);
if([[textView text] length] > restrictedLength){
textView.text=[temp substringToIndex:[temp length]-1];
}
}
The problem is that if the user edits a text image using the keyboard, then the user may not type more than 500 characters. But if the user copies the texts, the user can enter more than 500 characters. Can i deal with this?
source
share