title: Limiting the number of lines within a UITextView
body: <p>I'm well aware this question has been asked but I cannot find a valid answer.
  Using a combination of prior solutions I've come up with this code:</p>
  
  <pre><code>- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)string
  {
      int numLines = notesTextView.contentSize.height / notesTextView.font.lineHeight;
          if (numLines &lt;= 8)
          {
              return true;
          }
          return false;
  }
  </code></pre>
  
  <p>This does not work because the number of lines is counted prior to the additional text so we are still taken a line beyond what we want and are then trapped on it as no further editing is possible.</p>
  
  <p>I've also tried solutions that detect "\n" entries but this doesn't work either as we can reach new lines naturally without pressing return.</p>