UILabel view disappear when the height greater than 8192

六眼飞鱼酱① 提交于 2019-12-08 19:09:42

问题


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).

Is this an iOS bug?

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

UPDATE

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;

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;

回答1:


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.

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.

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

See https://stackoverflow.com/a/1494496/669586




回答2:


I ran into this same issue with UITextViews, and came up with a fairly effective solution.

If you'd like to see it, check out my answer here!:

https://stackoverflow.com/a/37147533/2155673

It should be fairly easily to adapt for UILabels.



来源:https://stackoverflow.com/questions/14125563/uilabel-view-disappear-when-the-height-greater-than-8192

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!