Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UILabel view disappear when the height greater than 8192

Tags:

ios

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

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;
like image 480
Ray Shih Avatar asked Jan 02 '13 16:01

Ray Shih


1 Answers

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

like image 59
Sulthan Avatar answered Sep 25 '22 06:09

Sulthan