Is there a way to use non breaking spaces in UILabel text?
For example, I have label with 2 lines and line breaking mode set to word wrap. The content for this label is read from database, where it's stored as a string. Now sometimes my text in label looks like that:
lorem ipsum some text 1
but I want to display it like that:
lorem ipsum some text 1
so basicly, I need to force non breaking space between 'text' and '1'.
I've found some solution here, but I think it could work when the text is entered in source code file. In my case the text is in database.
Any suggestions?
Place your cursor where the nonbreaking space should be inserted. Alternately, if a regular space already appears where the nonbreaking space should be inserted, select the regular space (see figure 1). 2. Select Ctrl + Shift + Space on your keyboard to insert the nonbreaking space.
Non-breaking spaces, also known as no-break, non-breakable, hard or fixed spaces, are characters that look exactly like regular spaces. You cannot see the difference between a non-breaking space and a regular space either on the page or on most screens.
Use the no-break space (\u00a0) ex: @"hello**\u00a0**world!"
post.text = [postText stringByAppendingString: @"1\u00a0hour\u00a0ago."];
U+00A0 / no-break space / Common Separator, space
from: http://en.wikipedia.org/wiki/Whitespace_character
For Swift:
let sentence = "Barcelona, Real Madryt, Juventus Turyn, Bayern Monachium" let sentencewithnbsp = String(map(sentence.generate()) { $0 == " " ? "\u{00a0}" : $0 })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With