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

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.

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

You should set the line break to character wrap, because the letters after the space will be recognized as a word.

Hey I know this is late but I just figured out that you can cheat the system by adding a bunch of spaces at the end of the text.

If text of UILable may be changed, then it's still possible to use quick-dirty hack with "\n" - new line symbol.
Text "Aaaaaaaaaaaaaa bbb cccccccccc\ndddddd" will force UILabel to display:
Aaaaaaaaaaaaaa bbb cccccccccc
ddddddd
In Interface Builder new line can be inputted with Ctrl + Enter

If u use wordWrap, it tries to keep words in full form, as a result of this, it goes to next line. If you use character wrap, it will break on characters, and push the chars onto next line.

For Example:-
My name is ABCXXXX and I (have space here)
love myself.
Solution:-
Use NSMutableAttributedText and write love\n. It will make the "love" be in the space myself in the next line.

Related

NSTextView - using up/down arrows moves paragraphs not lines

I have an app that runs on iOS and uses UITextView to display rich text, and also runs on Mac and uses NSTextView to display rich text. These are separate apps, but with a lot of shared code. In both cases, the {NS,UI}Textview is programmatically created and placed on a canvas.
{NS,UI}TextView will wrap long lines of text as required. Long lines are called paragraphs and have NSParagraphStyles that can be applied across the whole paragraph (line spacing, head indent etc). Each paragraph is delineated by a "\n" character (or one of the Unicode equivalents). Paragraphs wrap across multiple lines, if required.
On iOS, when you have a long paragraph covering multiple lines... if you use the down/up arrow keys, the cursor moves up and down by lines (i.e. possibly within the same paragraph), which is as you expect.
On the Mac, with the same setup, the up/down arrow keys move the cursor up and down by paragraphs (i.e. multiple lines), which is very much not what you expect.
I have attached videos of the two cursor movements so you can see what happens.
I use the same code to create the {NS,UI}TextView, and I can't see why there is a difference.
Does anyone know what's going on here? I have not interfered with the arrow key handlers in any way (although I do implement textViewDidChangeSelection: in the delegate, and can confirm that the selection is changing per my comments above).
Any ideas would be most appreciated!
Thx.
iOS Cursor Down in a UITextView.
Mac Cursor Down in an NSTextView.
Found it! It was an errant calculation in the delegate function DoCommandBySelector.

Is there a way to use non-breaking spaces in a UILabel in a launch screen?

I would like to ensure that names in a multi-line copyright string on the launch screen do not get split by line breaks on different devices. Inside a view controller with a UILabel outlet textLabel, the escape sequence "\u{00a0}" works programmatically:
textLabel.text = "Lots of text before... Firstname\u{00a0}Lastname... and after."
It displays the string with the escape sequence replaced by a space and the words either side always appear on the same line.
However, I can't get it work by putting it in as the value in a UILabel in Interface Builder - either in LaunchScreen or any other View Controller. It just displays the string with the codes left as typed. I've tried all the various combinations of \u, \U, \\u, \\U, \x+, etc. suggested in several SO questions to no avail. I think intervening in the display of the launch screen programmatically is impossible.
Have I missed something?
Don't use \u{00a0} in the text you enter into the storyboard. Enter an actual non-breaking space. The easiest way is to type ⌥-space (option-space).
If you ever need to enter any other special characters, another option is to use the standard Character Viewer. Select Emoji & Symbols from the Edit menu to bring up the Character Viewer. Then find the desired character that you wish to put in a label. You can do this in Swift code as well instead of typing cryptic Unicode escape sequences into your strings.

UILabel text wrong new line when has special character

Details of the issue :
When display text inside UILabel and almost the text fill complete line, if you add one more character with spacial character such as "ً" (check number 1) , it cuts first letter of text and put it in line alone(check number 2) and the rest of text in other line (check number 3)
Please note that the issue happening in the Facebook app and iOS note app
Try setting the linebreak mode to word wrap.
This may help.
Another option, try using textview instead of label.

Space at end of text not visible in right-aligned UITextField

I have a right-aligned UITextField. Initially spaces did not appear at the end of the text when editing. This I solved using this: replacing #" " with the non-breaking "\u00a0".
The above, however, only shows the space while editing the text field.
How do I also make spaces at the end of the text visible when the text field is not being edited?
Seems like triazotan has a solution involving replacing non breaking space for space https://stackoverflow.com/a/20129483/1247248
rednaw has some potentially better version, but someone was complaining of weird side effects
https://stackoverflow.com/a/22512184/1247248
I ended up going with the version of this solution suggested by meaning-matters https://stackoverflow.com/a/22211018/1247248 and that worked for me.
EDIT
It looked like a good fix but I found a problem. When you select inside the text and type the cursor jumps to the end of the line. Turns out I should have gone with triazotan's version
https://stackoverflow.com/a/20129483/1247248

How do I do a manual line break in an jQuery Mobile button?

I want to have a button with multiple lines. I could add white-space:normal but that does not allow manual line breaks. I have tried with <br> and
but they don't work as a jQM button is text only.
Note that I do not want automatic line-breaks, but I want to decide myself where to put them.
Nor do I want to change the height of the button. No, I want to add extra linebreaks.
i.e. I want to be able to have a button with
Text
like
this
instead of
Text like this
Is there a way around this limitation?
Ok, there is a way to do it. Since I use GWT I can do
JQMButton b = new JQMButton("dummy text");
b.getElement().setInnerHTML("this<br>text<br>works");
a couple of ways to do it
reduce the width of your button, the text would lay out itself in lines
do a shift-enter while typing the text or try a '\n' like this Text \n like \n this

Resources