sizeWithFont: constrainedToSize: with UITextView is (sometimes) not creating correct height - iPhone

霸气de小男生 提交于 2019-12-12 14:19:35

问题


I am using the following code to determine the height needed for a UITextView that is being added to a UITableViewCell, and also to determine the height for each UITableViewCell.

This works 90% of the time, but some incoming data (always the same incoming data) comes up short. If I allow scrolling within the UITextView, I can see that all the text is in the UITextView - but the UITextView does not have enough height to display all the text.

There does not appear to be anything wrong with the text that is 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 then create a frame with frame = CGRectMake(boundsX, yPosition, 230, size.height); and assign that frame to the UITextView , it (sometimes) comes up short.


回答1:


don't use UITextView. seems TextView have margin&padding configured by apple.
using UILabel instead. (don't forgot to set EnableMultiLine to YES).




回答2:


If table is in group mode, watch out for paddings. At the time of cellForRowAtIndexPath or heightForRowAtIndexPath, cell has screen width, not with padding of group style table.



来源:https://stackoverflow.com/questions/4596028/sizewithfont-constrainedtosize-with-uitextview-is-sometimes-not-creating-cor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!