8

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;
Ray Shih
  • 933
  • 8
  • 18

2 Answers2

7

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

Community
  • 1
  • 1
Sulthan
  • 128,090
  • 22
  • 218
  • 270
0

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.

Community
  • 1
  • 1
Fateh Khalsa
  • 1,326
  • 1
  • 15
  • 19