I have a UITextView
that I need to resize so that it has a width that stretches to fill the screen but variable height so that it is just big enough to show all the text. When the resizing takes place it should make the UITextView
the minimum possible height so that it fits the in.
In order to do this I have been using the following code:
textView.text = textMessage;
[textView sizeToFit];
CGRect rect = textView.frame;
rect.size.height = textView.contentSize.height;
textView.frame = rect;
When I do this it doesn't seem to make the UITextView the minimum height possible. It appears that there is some excess space left below. Here is an example (I have set the background colour to red in order to illustrate my point):
Please could someone advise why this is happening and how I can resolve the issue? Please note that the UITextView is located within a custom UITableView cell. This cell uses the Autoresizing masks to stretch horizontally to fill the screen depending on the orientation.
I have spend ages trying to get this to work but I don't see why there is excess space at the bottom and also when I rotate the device the height of the UITextViews all seem to remain the same (even though I call the [UITableView reloadData]
method which I have also defined the row heigh method for).