Search code examples
ioslaunch-screen

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?


Solution

  • 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.