UITextView text cut off when there is a large amount of text(文本量大时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文本被截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:文本量大时UITextView文本被截断
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01