SizeWithFont: constrainedToSize: with UITextView (sometimes) the correct height is not created - iPhone

I use the following code to determine the height needed for UITextViewwhich is added to UITableViewCell, as well as to determine the height for each UITableViewCell.

This works 90% of the time, but some incoming data (always the same incoming data) ends. If I enable scrolling in UITextView, I see that all the text is in UITextView, but UITextViewdoes not have enough height to display all the text.

There seems to be something wrong with the text being read, no special or hidden characters, etc.

UIFont *font = [UIFont fontWithName:@"ArialMT" size:14];
CGSize withinSize = CGSizeMake(230, 10000); 
CGSize size = [currentTimelineText sizeWithFont:font constrainedToSize:withinSize lineBreakMode:UILineBreakModeWordWrap];

When I create a frame with frame = CGRectMake(boundsX, yPosition, 230, size.height);and assign frame UITextView, it (sometimes) becomes short.

+3
source share
2 answers

do not use UITextView. it seems that TextView has margin & padding set up by apple.
using UILabel. (Remember to set EnableMultiLine to YES).

+6
source

If the table is in group mode, pay attention to the scroll. During cellForRowAtIndexPath or heightForRowAtIndexPath, the cell has a screen width rather than populating a group style table.

+2
source

Source: https://habr.com/ru/post/1783432/


All Articles