2

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.

Colas
  • 3,225
  • 3
  • 25
  • 61
  • try to replace / by \/ ? – ejanowski May 13 '15 at 09:03
  • @Colas i have posted answer please check it. – Ashok Londhe May 13 '15 at 09:09
  • '/' is probably seen as a word separator and there may be nothing you can do about it. If anything the requirement for most people may be that it does break the line after the '/' so things look better rather than leaving huge spaces at the end of lines. Why not avoid '/' and simply put "UI or UX" or "UI and UX" or "UI & UX" which is how most people read '/' anyway. – Rory McKinnel May 13 '15 at 09:12
  • @Colas try my answer now i know it will help you definitely. please replay after solving your problem. – Ashok Londhe May 13 '15 at 09:15
  • @Colas please mention your expected output in your question. – Ashok Londhe May 13 '15 at 09:16
  • possible duplicate of [In a UILabel, is it possible to force a line NOT to break in a certain place](http://stackoverflow.com/questions/25392888/in-a-uilabel-is-it-possible-to-force-a-line-not-to-break-in-a-certain-place) – pNre May 13 '15 at 09:27
  • @pNre My question is more specific. But, I admit that I have copied the title ;-) – Colas May 13 '15 at 14:30

2 Answers2

4

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.

Rory McKinnel
  • 7,730
  • 2
  • 15
  • 28
-2

Try this...

self.label.text=[self.label.text stringByReplacingOccurrencesOfString:@"/" withString:@" "];
Ashok Londhe
  • 1,462
  • 10
  • 28