UITextView text is disabled when there is a large amount of text

I have a subclass of UITableViewCell containing a UITextView where scrolling is disabled. I set its frame like this, in my layoutSubviews table view method in the table:

CGRect frame = self.bodyTextView.frame; CGSize size = self.bodyTextView.contentSize; frame.size = size; self.bodyTextView.frame = frame; 

This has been working fine for some time, but I noticed that in the case when I have a particularly large amount of text, the text is cropped. I set the background color of the text frame to orange to check if the frame was set correctly. Here is an example (I show only the bottom of the text view):

enter image description here

The frame is the correct size based on the text (in this case 1019 pixels), but the text stops in front of the bottom of the text view. I also saw how the text is cut off partially through the line (i.e. the text of the last visible line of text is cut off halfway horizontally). Does anyone know what is going on here?

A few other points:

  • Text views work well for all table view cells with shorter content.
  • If I increase the amount of text in the above example, the height of the text view increases, but the text is still turned off in the same place.
+4
ios cocoa-touch uitableview uitextview uiscrollview
May 30 '13 at 12:49
source share
2 answers

According to this and similar answers, the problem may be that "the correct content size is only available after adding a UITextView to the view ... Until it is equal to frame.size"

I would suggest you calculate the height in a different way, for example -sizeWithFont: or -sizeTofit

+4
May 30 '13 at 13:22
source share

Use this to get textSize.

 // find the text width; so that btn width can be calculate CGSize textSize = [@"YOUR TEXT" sizeWithFont:[UIFont fontWithName:@"Arial" size:20.0] constrainedToSize:CGSizeMake(320.0f, 99999.0f) lineBreakMode:UILineBreakModeWordWrap]; 

and then set the height using this as:

 CGRect frame = self.bodyTextView.frame; frame.size = textSize; self.bodyTextView.frame = frame; 

Hope this helps you.

+1
May 30 '13 at 13:12
source share



All Articles