UILabel wrong word wrap in iOS 11

studentbi picture studentbi · Sep 13, 2017 · Viewed 9.2k times · Source

I have problem with application using XIBs without autolayout. I don't know if this is important information.

I have UILabel with 2 lines using word wrap. In iOS 10 word wrap was working correctly, and first line contained one word + special character, for example ampersand. Example:

UiLabel on ios 10

Then on iOS 11 word wrap is working somehow wrong and puts ampresand to the second line:

UiLabel on ios 11

This is problematic as longer words, that normally fitted on second line now are not being shown correctly. Any idea what has changed? I know about safeArea but it doesn't look like reason. Any ideas how to move that ampersand to the top where is plenty of space for it?

Rest of the settings: size inspector

Answer

brynbodayle picture brynbodayle · Oct 23, 2017

This could very likely be an intentional change by Apple to prevent widowed lines. From a design perspective, it is preferred to avoid having a single word on a line of text. So it seems that UILabel now breaks the line in a way that the second line of text always has at least 2 words on it.

It is surprising that there is no documentation or way to disable this behavior though.

enter image description here

Also here's a good article about "widowed" and "orphaned" text.