文本量大时UITextView文本被截断 [英] UITextView text cut off when there is a large amount of text

查看:19
本文介绍了文本量大时UITextView文本被截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITableViewCell 子类,其中包含一个 UITextView 滚动已关闭.我在表格视图单元格 layoutSubviews 方法中这样设置它的框架:

I have a UITableViewCell subclass that contains a UITextView where scrolling is turned off. I set its frame like this, in my table view cell layoutSubviews method:

    CGRect frame = self.bodyTextView.frame;
    CGSize size = self.bodyTextView.contentSize;
    frame.size = size;
    self.bodyTextView.frame = frame;

这已经有一段时间了,但我注意到在我有特别大量的文本的情况下,文本会被截断.我已将文本视图框架背景颜色设置为橙色,以便验证框架设置是否正确.这是一个示例(我只显示文本视图的底部):

This has been working fine for some time, but I've noticed that in a case where I have a particularly large amount of text, the text is getting cut off. I've set the text view frame background color to orange so I could verify that the frame was being set correctly. Here is an example (I am only showing the bottom portion of the text view):

框架是基于文本的正确大小(在本例中为 1019 磅),但文本在文本视图底部之前停止.我还看到文本在一行中被截断(即最后一个可见文本行的文本被水平截断一半).有谁知道这里发生了什么?

The frame is the correct size based on the text (in this case 1019 points), but the text stops before the bottom of the text view. I have also seen the text get cut off part way through a line, (ie the text of the last visible line of text is cut off half way through horizontally). Does anyone have an idea what is happening here?

其他几点:

  • 文本视图适用于我所有内容较短的表格视图单元格.
  • 如果我在上面显示的情况下增加文本量,文本视图高度会增加,但文本仍然会在同一位置被截断.

推荐答案

根据this 和类似的答案,问题可能是正确的 contentSize 仅在 UITextView 添加到视图后可用......在此之前它等于 frame.size"

According to this and similar answers, the problem could be that "the correct contentSize is only available after the UITextView has been added to the view ... Prior to that it is equal to frame.size"

我建议您以不同的方式计算高度,例如 -sizeWithFont: 或 -sizeTofit

I'd suggest you to calculate the height in a different way, like -sizeWithFont: or -sizeTofit

这篇关于文本量大时UITextView文本被截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆