UILabel wraps incorrectly in iOS 11

It looks like iOS has changed how labels are drawn. Rather than use the entire width, it wraps too early:

My guess is it is trying to make the minimal rectangle it can. However, this is incorrect, because its width is in fact basically the same as the balloon. The word "more" should be on line one for a more consistent look.


iOS 9 and 10 used a standard wrap, as if typing into a word processor.


Are there any flags I can use to get the old behavior, of full-width wrap?

Replies

Looks like the picture may not be embedded? http://www.pensee.com/dunham/pictures/wrap.png

And I think UIButton has the same problem. I have multi-line buttons and I want them to look like normal text, wrapped to the full width of their bounds.

It would be great if there was away to disable this new style of wordwrap. Unforunately documentation on the change does not exist. Have you figured away around the new change? We are having a problem with wordwrap being inconsistent between UILabels and CATextLayers


Found some posts from others with the same issue:

https://stackoverflow.com/questions/46200027/uilabel-wrong-word-wrap-in-ios-11


https://stackoverflow.com/questions/46923039/get-each-line-of-text-in-a-uilabel/47007494#47007494

No, I used a DTS incident and they said it was not possible.

For anyone who wants to refer to it in their own bugs: I filed Radar 36021540.

Running into the same issue here - we have large header titles that are no longer wrapping correctly. I assume that since you filed a DTS ticket they would have suggested this, but curious if you're trying both AutoLayout and ManualLayout - are you seeing the same issue with both? We are currently using AutoLayout for this, but about to try manual to see if there's a difference.

It looks like the undocumented

NSAllowsDefaultLineBreakStrategy

(mentioned in https://stackoverflow.com/questions/46200027/uilabel-wrong-word-wrap-in-ios-11/) restores standard wrapping, rather than an apparent attempt to avoid orphans.

I did not try manual layout (in the overall scheme of things I use a stack view, so that would be tricky), but DTS did not suggest it. But the bounds are correct so I don’t think that was ever the issue.

To add a bit of information to this problem or bug:


A label with a multi-line attributed string was placed using IB while View As set to an iPhone 8.

(Making a width of 343 with 16 point leading and trailing constraints to the safe area.)

The attributed text using center alignment and the label set to 0 lines.

Changing the View As set to an iPad,

the label with is now correct at 736 for the iPad and

the 16 point leading and trailing constraints to the safe area still intact.

The attributed text, however, remains as originally laid out:

appears centered in the first 343 points of the (now) 736 width label.

So, the entire body of the attributed text is left justified to the leading 343 points of the 736 width label,

but remains center justifed within that 343 point width area.

To note, another label, with the same constraints to the leading and trailing to the safe area, properly centers whether it is on the 343 width device or on the 736 width device. The only difference is that it is set to 1 line, not 0 lines.


I point this out, because the label is for some reason causing the word wrapping to occur at 343 points instead of the 736 point width. Once the label was created while View As set to an iPhone 8, it seems like it is stuck with the iPhone 8 safe area width. Changing the attributed text does not seem to change this imaginary early word wrap.


Deleting the label, setting IB View As set to an iPad, does however, allow the very same attributed text to honor the full 736 point width of the label for word wrap!