问题描述
我正在使用以下代码来确定要添加到UITableViewCell
的UITextView
所需的高度,并且还要确定每个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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!