sizeWithFont: constrainedToSize: with UITextView is (有时) not creating correct height-iPhone[英] sizeWithFont: constrainedToSize: with UITextView is (sometimes) not creating correct height - iPhone

本文是小编为大家收集整理的关于sizeWithFont: constrainedToSize: with UITextView is (有时) not creating correct height-iPhone的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

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

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

似乎没有读取的文本,没有特殊或隐藏字符等任何问题.

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时,它(有时)出现很短.

推荐答案

不要使用UITextView.似乎TextView具有Apple配置的边距和填充.
而是使用UILabel. (不要忘记将enablemultiniline设置为是).

其他推荐答案

如果表处于组模式,请注意桨板.在CellForrowatIndExpath或Height ForrowatIndExpath时,单元格有屏幕宽度,而不是组样式表的填充.

本文地址:https://www.itbaoku.cn/post/2091164.html

问题描述

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.

推荐答案

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

其他推荐答案

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.