14

I have a right-aligned UITextField. Initially spaces did not appear at the end of the text when editing. This I solved using this: replacing @" " with the non-breaking "\u00a0".

The above, however, only shows the space while editing the text field.

How do I also make spaces at the end of the text visible when the text field is not being edited?

Community
  • 1
  • 1
meaning-matters
  • 21,929
  • 10
  • 82
  • 142

1 Answers1

9

Seems like triazotan has a solution involving replacing non breaking space for space https://stackoverflow.com/a/20129483/1247248

rednaw has some potentially better version, but someone was complaining of weird side effects https://stackoverflow.com/a/22512184/1247248

I ended up going with the version of this solution suggested by meaning-matters https://stackoverflow.com/a/22211018/1247248 and that worked for me.

EDIT

It looked like a good fix but I found a problem. When you select inside the text and type the cursor jumps to the end of the line. Turns out I should have gone with triazotan's version https://stackoverflow.com/a/20129483/1247248

Community
  • 1
  • 1
Marc
  • 1,159
  • 17
  • 31
  • 1
    Interesting, I seem to have answered my own question somewhere else :-) Thanks dude! – meaning-matters Aug 01 '14 at 13:19
  • not working properly for me, I have to tap spacebar two times to start adding space at the end of string and same happens in case of backspace button to delete last space characters. – ViruMax Aug 11 '14 at 13:35
  • 1
    non breakable character \U0A00 should not be used because it yields spcial character while parsing so anybody have another solution ? – Shobhakar Tiwari Aug 14 '14 at 07:43
  • 1
    None of these work anymore on iOS 15 and up – beowulf Oct 07 '22 at 14:21
  • Not working on iOS 16 either. Couldn't find a solution, had to update UI to use left alignment. – mkai Oct 14 '22 at 16:00