当有大量的文本时,UITextView文本被切断 [英] UITextView text cut off when there is a large amount of text

查看:200
本文介绍了当有大量的文本时,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?

其他几点:


  • 文字检视适用于所有

  • 如果在上述情况下增加文本数量,文本视图高度会增加,但文本仍会在同一位置被截断。

推荐答案

根据这个和类似的答案,问题可能是正确的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天全站免登陆