Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UILabel word wrapping brings extra word to next line when there is enough space for it

Tags:

ios

uilabel

Under certain circumstances, UILabel seems to bring an extra word to new line even when there is enough space for it, for example,

enter image description here

If one more word is appended,

enter image description here

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,

enter image description here

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,

enter image description here

And the constraints (in the first two cases, the trailing ),

enter image description here

Is there any reason for this particular behaviour and can I fix this? It looks weird in this way leaving that space emptied.

like image 726
alanlo Avatar asked Feb 23 '18 02:02

alanlo


People also ask

How do you wrap text in UILabel?

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.

Which attribute of the tag is used to turn off the word wrapping?

Use the &nbsp; 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>.

What is UILabel?

A view that displays one or more lines of informational text.


1 Answers

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

like image 127
Abuzeid Avatar answered Oct 02 '22 22:10

Abuzeid