IOS 7 UITextView altitude resizing quirk

Using the information I got from several answers found here on stackoverflow, I was able to set the height correctly UITextView'susing:

[bookQuoteTxtView sizeToFit];
[bookQuoteTxtView layoutIfNeeded];

I am doing this because UITextView, obviously, it will contain different amounts of text as a result of what the user could select on the previous screen.

However, I still run into one weird problem.
It appears that when the text that is passed in UITextViewcontains a line break, it throws out the entire height.

Here is the text without any breaks:

enter image description here

And here is the same text with a few tears thrown in the middle:

enter image description here

( , UITextView ScrollView, ), UITextView's , off - - .

, UITextView:

// BookQuote TextView:
bookQuoteTxtView = [[UITextView alloc] initWithFrame:CGRectMake(5, 30, 310, 80)];
bookQuoteTxtView.backgroundColor = [UIColor orangeColor];
bookQuoteTxtView.font = [UIFont fontWithName:@"Arial" size:15];
bookQuoteTxtView.text = [NSString stringWithFormat:@"%@", bookObject.bookQuote];
[bookQuoteTxtView sizeToFit];
[bookQuoteTxtView layoutIfNeeded];
bookQuoteTxtView.editable = NO;

[scroller addSubview:bookQuoteTxtView];

// Now get the HEIGHT of the Book-Quote TextView:
CGRect textViewFrame = bookQuoteTxtView.frame;
CGFloat textViewFrameHeight = bookQuoteTxtView.contentSize.height;
textViewFrame.size.height = textViewFrameHeight;
bookQuoteTxtView.frame = textViewFrame;

, , UITextView. , , UITextView's . , .

, ... , , "\n" DO, , , / , Sqlite3, - .
, .

, :

  // Book Quote:
  char *bookQuoteChar = (char *)sqlite3_column_text(statement, 4);
  NSString *bookQuoteString;
  if (bookQuoteChar == NULL) {
      bookQuoteString = @"N/A";
  }
  else {
      bookQuoteString = [[NSString alloc] initWithUTF8String:bookQuoteChar];
  }

, , , , .
, , - - .

+4
1

, , contentSize UITextView.

textView.text    = @"text from DB";
CGRect rect      = textView.frame;
rect.size.height = textView.contentSize.height;
textView.frame   = rect;

, . , !

+1

All Articles