iosuilabelcore-texthyphenation

In a UILabel, is it possible to force a line NOT to break at slash?


Example: My text is @"This is a great UI/UX feature".

A better example: @"5/17 of this quantity".

Is it possible to force the line NOT to break at the / (the slash)?

I'm looking for a general way of doing, since I have others sentences with slashes.


Solution

  • An option would be to use a Unicode character rather than normal slash.

    There are non breaking versions in unicode for space and hyphen. If you were ok to change to using - rather then /, this using @"UI\u2011UX" will show UI-UX and not break the line at the hyhen.

    There does not seem to be an equivalent non break for slash, however you could try another flavor of slash. e.g. UI\u2044UX will not line break but show UI/UX using the FRACTION SLASH. See http://www.fileformat.info/info/unicode/char/2044/index.htm.

    I tried this just now on a UILabel and using the unicode characters will prevent line break. You just need to decide which slash or alternative you want to use.