I have a non-scrollable UITextView with it\'s layoutManager maximumNumberOfLines set to 9, which works fine, but, I cannot seem to find a method in NSLayoutManager that rest
I created a test VC. It increases a line counter every time a new line is reached in the UITextView. As I understand you want to limit your text input to no more than 9 lines. I hope this answers your question.
#import "ViewController.h"
@interface ViewController ()
@property IBOutlet UITextView *myTextView;
@property CGRect previousRect;
@property int lineCounter;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.myTextView setDelegate:self];
self.previousRect = CGRectZero;
self.lineCounter = 0;
}
- (void)textViewDidChange:(UITextView *)textView {
UITextPosition* position = textView.endOfDocument;
CGRect currentRect = [textView caretRectForPosition:position];
if (currentRect.origin.y > self.previousRect.origin.y){
self.lineCounter++;
if(self.lineCounter > 9) {
NSLog(@"Reached line 10");
// do whatever you need to here...
}
}
self.previousRect = currentRect;
}
@end