UILabel 视图在高度大于 8192 时消失 [英] UILabel view disappear when the height greater than 8192

查看:17
本文介绍了UILabel 视图在高度大于 8192 时消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将大字符串分配给 UILabel.并且,将此标签添加到滚动视图中.
当 UILabel 高度大于 8192pt(即 2^13)时,UILabel 消失.

Assigning large string to UILabel. And, adding this label into a scroll view.
The UILabel disappear when the UILabel height larger than 8192pt (which is 2^13).

这是 iOS 错误吗?

Is this an iOS bug?

我应该使用其他实现来呈现如此数量的字符串吗?
我应该在单元格中使用表格视图吗?

And should I use other implementation to render such amount of string?
Should I use table view with cell?

更新

显示 UILabel 的代码:

The code that will display the UILabel:

UILabel *label = [[UILabel alloc] init];
label.backgroundColor = [UIColor clearColor];
label.text = rumor.displayText;
label.frame = CGRectMake(0, 0, self.view.frame.size.width, 8192);
label.lineBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 0;

UILabel 确实消失的代码

And the code that UILabel does disappear

UILabel *label = [[UILabel alloc] init];
label.backgroundColor = [UIColor clearColor];
label.text = rumor.displayText;
label.frame = CGRectMake(0, 0, self.view.frame.size.width, 8193);
label.lineBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 0;

推荐答案

首先 - 它不一定是错误.这只是未定义的行为.请注意,对于每个组件,当组件停止正常工作时,都会有一些大小上限.8192点似乎是一个下限,但仍然是纵向模式下iPad屏幕的8倍左右.

First of all - it doesn't have to be a bug. It is just undefined behavior. Note that with every component, there will be some upper size limit when the component stops working correctly . 8192 points seems to be a low limit but still it's about 8 times the iPad screen in portrait mode.

你不应该把视图弄得那么大.请注意,UIView 通常会渲染到内存中并进行缓冲,以加快重绘速度.高度为 8192,缓冲区必须非常大.

You are not supposed to make views that big. Note that UIViews are often rendered into memory and buffered, to make redrawing faster. With 8192 height, the buffer will have to be very big.

将文本拆分为多个 UILabel(例如按段落)肯定会有所改进.

Splitting the text into several UILabels (e.g. by paragraph) would definitely be an improvement.

参见https://stackoverflow.com/a/1494496/669586

这篇关于UILabel 视图在高度大于 8192 时消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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