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.
In LibreOffice Calc, If you enter text in a Standard cell ending with an underscore followed by a number, then the text is converted in the following way: the underscore is removed and the number is set in a small font (subscript).
Exemple:
If I enter TEST_1 in a cell and press Enter, then the content of the cell is replaced by TEST₁
How is it possible to cancel this behavior ?
The autocorrect behavior depends on the language.
In my case the Autocorrect options (in menu Tools->Autocorrect) were set to French (France).
The autocorrect rules causing this problem were in the form
.*_0 converted to ₀
It is possible to delete these rules to avoid the problem.
I want to get the last word from the typed sentence in UITextView. For example "Apple i", from this example i need to get the last letter 'i' coming after " "(empty space). I want to do the functionality while the user typing in UITextView. How can i get the users first letter of the word after from empty space(" ")? Can anyone please help to solve this problem? Thanks in advance.
Here is the string logic.
return [[textView.text componentsSeparatedByString:#" "] lastObject];
You can put this check in your UITextViewDelegate method textView:shouldChangeTextInRange:replacementText:. Don't forget to return YES here. You could also use textViewDidChange:.
Does anyone have a solution to this? I did some google-ing and came up with zilch. I have no idea why a UITextView would replace with a space, but it is indeed happening.
It is easy to duplicate - type the non breaking space code I placed in the title of this question into a UITextView, and then look at the text property, you'll see a space.
Is there a fix for this?
You are out of luck. This is most likely a bug, and it seems it has been filed with Apple.
See post UITextField converts non-breaking spaces to spaces?.
As a workaround you can use the delegate method textViewDidChange: to catch the keyboard input to keep track of any occurrences and then react accordingly.
Cheers,
Sascha
Would I use a UILabel for that? Or is there something better?
It depends on what you want to achieve. If you just want a multi-line label, then you can use UILabel with the numberOfLines parameter set to something other than 1 (set it to zero if you don't care how many lines are used). If you need to let the user edit the text, then a UITextView is the way forward. Line breaks are indicated using the \n character, not the /n sequence as Emil incorrectly wrote.
You can use a UITextView, and write \n where you want the new lines.
Hey!\nHow are you?\n\n\nYOU: I am fine.\nME: That's great! will display:
Hey!
How are you?
YOU: I am fine
ME: That's great!