0

Under iOS I'm wondering if there is a kind of "extra fragile" space that I could put in to a string.

If I display it in a UILabel (or other control), and the text needs to be split over >1 line, then the layout would try to split on a a fragile space if it possibly can.

Eg, if <> is a fragile space symbol, then the string "All on one line if possible<>but this on another line if needed." would display as:

All on one line if possible
but this on another line if needed.

… assuming that there wasn't room for the whole string on one line.

Or perhaps the concept is more a "Newline here if you need to".

Maybe something with ranges in NSAttributedString that can describe where breaking should be preferred? Or some other way to specify this to a label?

Benjohn
  • 13,228
  • 9
  • 65
  • 127
  • The [unicode zero width space](http://stackoverflow.com/questions/14615268/html-opposite-of-non-breaking-space) sounds close. No idea if this works with a `UILabel` though. – Benjohn Jan 18 '17 at 09:02
  • Another approach might be to observe the text field after auto-layout and if it is broken over more than one line, modify the content to be split over two lines and cause a second auto-layout layout pass. – Benjohn Jan 18 '17 at 09:06
  • did you find a solution for this? Maybe even a solution which "survives" searching, i.e. "Hel<>lo" is also found by "Hello"? – swalkner Feb 28 '17 at 14:52
  • I didn't, no, sorry. … I think that if you really want to achieve this, you could probably do it by hooking the view layout pass, checking if your view is over >1 line, and changing the contained string to have a newline at the desired point. This is complex and not very general / reusable, though. – Benjohn Feb 28 '17 at 21:53

0 Answers0