I searched for solutions and found the following code snippet. But I do not know how to use it, unfortunately.
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)string { NSUInteger newLength = [textField.text length] + [string length] - range.length; return (newLength > 25) ? NO : YES; }
For testing only, I configured IBACTION
-(IBAction)checkIfCorrectLength:(id)sender{ [self textView:myTextView shouldChangeTextInRange: ?? replacementText: ?? ]; }
What should I pass for shouldChangeTextInRange
and replacementText
? Or am I completely mistaken?
source share