本文介绍了sizeWithFont:constrainedToSize:使用UITextView(有时)无法创建正确的高度-iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码来确定要添加到UITableViewCellUITextView所需的高度,并且还要确定每个UITableViewCell的高度.

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.

这在90%的时间内有效,但是一些输入数据(总是相同的输入数据)出现不足.如果允许在UITextView中滚动,则可以看到所有文本都在UITextView中-但是UITextView的高度不足以显示所有文本.

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];

然后我用frame = CGRectMake(boundsX, yPosition, 230, size.height);创建框架并将frame分配给UITextView时,它有时会显得很矮.

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.

推荐答案

不要使用UITextView.似乎TextView具有由Apple配置的边距和填充.
使用UILabel代替. (不要忘记将EnableMultiLine设置为YES).

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

这篇关于sizeWithFont:constrainedToSize:使用UITextView(有时)无法创建正确的高度-iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 13:38