Xcode 9 setting label with 0 lines to height of 14,600.5 in stack view

Viewed 2434

In Xcode 9 I am following along to the AppCoda tutorial to get started in iOS development. I noticed some odd behavior and am wondering if this is a bug or something I am not understanding with stack views in the Interface Builder (since the app does compile and displays correctly on my phone).

When I place the Label and set it as the third element in the stack view, a sibling of two other nested stack views, it appears fine if the default attributes are used. However, when I change the lines property from 1 to 0, the label and the adjacent stack view disappear from the interface builder.

Before

After

In the size inspector, the coordinates for the label changed from 0,208.5 to 0,-90. If I change these properties, the height of the label changes from 0,0 to 375,14600.5, and Xcode throws an error: Interface Builder does not support UILabel sizes larger than 10,000 by 10,000.

Is this a bug with Xcode, or is there some changed behavior with the lines attribute for this version of Xcode (the book currently covers Xcode 8).

5 Answers

Here's a solution. Select the label view and go to the size inspector. Under label preferences check the explicit size box. This prevents the stack view from collapsing when you put a multiple line label into it.

Set Size Inspector > Intrinsic Size > Placeholder, set width to none and height to say 30

From description: Setting a design time intrinsic content size only affects a view while editing in Interface Builder. The view will not have this intrinsic content size at runtime.

From Xcode Help: Use a placeholder intrinsic size to indicate a view’s width and height and avoid design time constraint ambiguity.

This is a bug in Xcode 9 - see https://github.com/lionheart/openradar-mirror/issues/18779. It only seems to affect how the canvas is drawn in Xcode: at least for me, my app still builds correctly. I first saw it after I upgraded to 9.0.1 from 9.0, and Xcode 9.1 still has the bug. I downgraded to 9.0, which doesn't appear to have this bug.

This has been reported as bug 30484038 on Apple's Bug Reporter (bugreport.apple.com) - I reported a similar error and they replied that it was a duplicate of 30484038. That bug is still marked "open". I've asked if there is a workaround or an expected time until it's fixed, but they haven't responded with an answer as yet.

I will try setting an explicit size for the affect UILabels to see if that serves as a workaround.

UPDATE: This bug appears to be fixed in Xcode 9.3. In my case, Xcode now draws labels properly when the lines property is set to 0. Also, in the release notes for 9.3 I found this under Interface Builder, Resolved Issues:

Toolbars or multiline labels in stack views no longer result in an Auto Layout misalignment on the canvas. This issue resulted in problems such as zero width multi-line labels, or in extra tall toolbars when an iPhone X was selected in the device bar. (35377301)

In xib, just set a temporary height constraint for label(like 100), and delete it. It will display the height you just set.(just the display height, not actual height).

I think it's because your text label is too long.

numberOfLines docs

This property controls the maximum number of lines to use in order to fit the label’s text into its bounding rectangle. The default value for this property is 1. To remove any maximum limit, and use as many lines as needed, set the value of this property to 0.

Basic on your constraints, your label can't fit into stack view. I suggest you divide your big UILabel into smaller pieces.

Related