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

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.

Related

Custom iOS keyboard - Custom font output

I am trying to create a custom keyboard using the app keyboard extension. I am happy with the layout but the output is depended on the UITextField's font.
Is there a way to force a different font (use special characters?) while using the keyboard ?
Thank you
It depends.
Text field (or any other view that draws text) uses 2 informations on how to show some text. One is the sequence of characters called String and the other one is how the string should be represented. The second one is then split it things like fonts, colors, line height, line breaking and wrapping...
So the keyboard alone is not enough to for instance present a certain part of word using different fonts. You need at least a bit of access to the item that represents the text. So if you have no access to your text field then the answer is; No, you can not fore a different font when using different keyboard.
If you do have the access then the answer should lie in NSAttributedString. It is a string you can assign to most items under attributedText. This class wraps your raw string and can add many properties to parts of text you want to change. That includes using a different font.
Another approach would be using HTML tags. Again you will need to process this using for instance NSAttributedString or display it with another element like web view.
I would try it with using NSAttributedString. Hook up to delegate and implement textField(: shouldChangeCharactersIn: replacementString:. The implementation itself may still not be easy though.

Split text if its content exceeds numbers line limit in Swift

Conditions:
UITextView that can contains X lines as maximum:disable scroll. (For example; max lines = 8)
A huge text content. (For example; 25 lines)
Language is English. (Word-wrap is compulsory)
How can I split text if its content exceeds numbers line limit?
I want to split text into array. Following the condition, the text should be split to 4 elements.
Update:
Actually what I want to achieve is like when I have a long text and I have the fix text container size (eg. UITextView) which cannot display all content, then there is a next button to reset container and display the left content. I thought that split string would help but it seems a wrong choice. I am trying what Matt's suggestion and hope the problem will be solved.
Your goal is not a good one. Instead of splitting the text into four arrays of text, it would be better to take advantage of Text Kit and let the layout manager split the text into four text containers (one NSLayoutManager, four NSTextContainers).
This could even be combined with your current use of a text view for display purposes: the four text containers could belong to four text views, and now you have four noneditable nonscrollable text views that automatically distribute the text between them, and you can just switch among those text views.
Here's an example with just two text views:
That's two UITextView objects governed by one NSLayoutManager, so that as the text becomes too long for the first text view it automatically flows into the second text view.
If you really wanted to, I suppose you could do what I just said and then use the layout manager to ask what it did, i.e. to read backwards from the line fragments to the glyphs to the character ranges and find out how it split the text into four text containers; but this seems silly when you consider that the problem is already solved before you even start to do that.

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

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.

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.

How do you add a superscript character into a Powerbuilder textbox?

Is there any way to do this in the Powerbuilder properties window for a datawindow's textbox?
That kind of depends on how you define "textbox", but in general the only way to mix normal and superscript text is with a richtext control. In PB 11.5, you can even use richtext as a column style.
Good luck,
Terry.
Yes. For the text control, you must select a font that has superscript characters (Arial does).
Go into the Windows Character Map (usually in the start menu under Accessories->System Tools) and select your font.
Then go to the superscript character that you want to place in your text control. Click it and then click the Select button to place it down in the character map text box.
Then click the Copy button.
Now you can return to PowerBuilder and paste this value into the properties window text area.
As long as the same font is selected for the DataWindow control as was selected in the character map it should show as your superscript character.
This same techinque can be done to include any of the Wingding type characters as well.
We ended up using two separate text fields. It's a butt-ugly solution, but it works. The superscript field has a smaller font and is nudged a little higher up.
I think newer PB versions support superscripts.
Thanks for the help.
Glenn
If you go to the character map - when you select your character it will show the keys to enter this character on the bottom right of the window.
Example : in Arial font - the ® (registered) mark is Alt + 0174
To enter these, turn your numlock on, hold the alt key down, and type 0 1 7 & 4 then let up on the alt key. You have to use the number keys on the number pad to do this the ones on the top of the keyboard dont work.
You can then enter your characters directly or do something like this :
ls_key = '®'
Actually I stumbled across a simpler solution. I copied and pasted a portion of the text from a pdf into the text property of a datawindow text contol. The superscript character simply pasted in. So I'm guessing that Dougman's solution would work too.
Example:
"™Trademark used under..."
Note: I'm using PB 9.0.1
Thanks for all the help,
Glenn

Resources