I am well aware that this question has been asked, but I cannot find the correct answer. Using a combination of the previous solutions, I came up with this code:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)string { int numLines = notesTextView.contentSize.height / notesTextView.font.lineHeight; if (numLines <= 8) { return true; } return false; }
This does not work, because the number of lines is counted before the additional text, so we still occupy a line other than what we want, and then delay it, since further editing is not possible.
I also tried solutions that detect "\ n" entries, but this does not work, since we can naturally reach new lines without pressing return.
source share