Original
I am currently working on an app where the user can resize the font in a UITextView up to 50pt. As it stands they can also edit the text in this UITextView with as many characters as they like (my boss wants to limit any kind of prescriptive behaviour). The UITextView then dynamically resizes vertically to cater for the amount of text. All well and good. However, once the height of this UITextView exceeds a certain size, any subsequent characters will be added but will be hidden from view, unless I allow the UITextView to be scrollable.
I would have to add that this is an edge case. However, because the app encourages this sort of behaviour there is a possibility that this limit could be encountered occasionally.
Am I right in thinking there is actually a limit on the height for a UITextView? Or is the issue potentially something else?
Edit
Okay maybe I’m misunderstanding my own situation. I failed to consider the fact that the textView sits within a tableViewCell, and what I am actually doing is resizing the cell as the textView size increases. Is there a limit on the height of a tableViewCell then?
Answer to my issue
Thank you @jere and @A-Live for your answers they helped a great deal. I know feel like such an idiot.
A-Live pointed out about max float values and that suddenly made me realise such an obvious and blatant mistake I had made.
In order to resize the textView appropriately a CGSize is established using constraints. In order to ensure the height was allowed to be as high as it wanted, a supposedly unreachable high number was used for the height constraint (1000). As you can guess, 1000 was not enough for the purpose of this and therefore the textView was stopping short. I guess this is why it is important to provide code.
CGSize textSize = [textView.text sizeWithFont:textView.font constrainedToSize:CGSizeMake(textView.frame.size.width - PADDING * 2, 1000.0f) lineBreakMode:UILineBreakModeWordWrap];
The most accurate answer to the updated question is @jere, and because this has been pointed out to me I will have to prevent the cell size from ever reaching that magic number of ‘2009’.
Note that if you want to set the height for only some cells and not all, you have to use the delegate method
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPathand return the height you want for your row there.You could also use the
rowHeightproperty but that applies to the whole table view.Now here’s an interesting part of the Apple docs regarding the delegate method:
So I guess that must be the max value or something. It would be kinda crazy if your cell goes beyond 200 or 300px anyways…