Under certain circumstances, UILabel seems to bring an extra word to new line even when there is enough space for it, for example,
If one more word is appended,
Even if I force the width of the label to become something like below, it still moves the word consists of "c"s to the next line,
I've tried twisting the configuration of the UILabel, but seems it behaves the same unless I set the line breaking mode to character wrap, below is the configuration for the above cases,
And the constraints (in the first two cases, the trailing ),
Is there any reason for this particular behaviour and can I fix this? It looks weird in this way leaving that space emptied.
If you set numberOfLines to 0 (and the label to word wrap), the label will automatically wrap and use as many of lines as needed. If you're editing a UILabel in IB, you can enter multiple lines of text by pressing option + return to get a line break - return alone will finish editing.
Use the entity for the non-breaking space character, when you want to make sure that a line isn't broken! Alternatively, use the NOWRAP attribute to disable word wrapping and the <BR> element to force line breaks where desired. Netscape includes two tags: <NOBR>... </NOBR>, and <WBR>.
A view that displays one or more lines of informational text.
this is the default behavior since iOS 11, to fix orphaned words. No way to shut it off
to fix it use the text as attributed text
or use UItextview and turn of the scroll, edit option
or use the custom label here Get each line of text in a UILabel
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With