Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Read Number of lines in UITextView

Tags:

I am using UITextView In my View , I have requirement to count number of line contained by textview am using following function to read '\n' . However this works only when return key is pressed from keyboard , but in case line warapper (when i type continuous characters i wont get new line char ) . How do i read new char when line is changed without hitting return key ?? Anybody has nay idea how to .. please share it .. I am follwing this link Link

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range   replacementText:(NSString *)text {     // Any new character added is passed in as the "text" parameter     if ([text isEqualToString:@"\n"]) {         // Be sure to test for equality using the "isEqualToString" message         [textView resignFirstResponder];          // Return NO so that the final '\n' character doesn't get added         return NO;     }     // For any other character return YES so that the text gets added to the view     return YES; } 
like image 292
santosh Avatar asked Aug 27 '10 15:08

santosh


1 Answers

In iOS 7, it should exactly be:

float rows = (textView.contentSize.height - textView.textContainerInset.top - textView.textContainerInset.bottom) / textView.font.lineHeight; 
like image 195
Soul Clinic Avatar answered Sep 29 '22 10:09

Soul Clinic