15

I just moved from xCode 4.x to xCode 5, along with making the jump to iOS 7. In the past, I have placed text with trailing spaces in a UILabel, and using right alignment leaves a little space to the right of the text. Since I have moved to xCode 5, this behavior seems to have changed. When the UILabel right-aligns its text, it appears to be ignoring the trailing spaces - and aligns the text as if there were no trailing spaces at all.

Has anyone else seen this behavior? Is there a way to add edge insets within xCode to adjust for this new behavior, or must it be done in code?

Rick Morgan
  • 603
  • 9
  • 14
  • I have seen exactly the same behaviour on iOS 7 devices. In my case, it was in an old app that I have not yet migrated to Xcode 5, so I am still building it with Xcode 4.6.3. This means that it is also affecting the iOS 6 compatibility mode. In this app, the reason that I had added these trailing spaces in the first place, was to overcome another UILabel bug: Right-aligned italic text is clipped at the right edge! So now I was forced to a new workaround in the same piece of code. This time, I ended up with a dirty fix, changing the text to center alignment and adjusting the frame dynamically. – Magnus Nov 14 '13 at 09:37
  • You might try using option-space (or alt-space) as this gives a different space character – amergin Nov 18 '13 at 13:20

4 Answers4

7

I am seeing the same behavior. I think the issue is not the change to xCode5 but when one changes to running under ios7. Apple appears to now be stripping all white space characters from within text blocks that will be displayed using UILabel that are being used to pad lines either at the beginning of a line or the end of a line. If multiple space characters are used within a line between two words, those characters are not stripped.

We have been using UILabels to layout multiline blocks of text supplied from a markup language. Some of the text content needs to be center aligned but has spaces deliberately added to push a particular line of text to the left or to the right. This was recognized and works perfectly under ios6 but breaks under ios7.

Why has Apple made this change I wonder. Anyone else having this issue - any ideas for a fix for this? We are experimenting with a custom font which has a control character that looks like a space but is not.

lauriek334
  • 86
  • 2
  • Thanks. There are times in which I use spaces before the text on a button, in order to add more space between a button's graphic and its title (which I believe is internally a `UILabel`. I'm using center control alignment - that appears to be functioning as before. I haven't checked to see if the behavior of every form of text alignment (left, right, center) has changed. – Rick Morgan Sep 26 '13 at 22:10
  • I'm having this problem as well. Extremely frustrating. What's even stranger to me is that it appears it's only the trailing spaces that are affected -- leading spaces are still rendered. – DanM Nov 15 '13 at 19:17
  • And furthermore, the same screwy decision to ignore trailing spaces seems to be applied to the calculation for adjustsFontSizeToFitWidth as well. – DanM Nov 15 '13 at 19:20
1

Have a look at UILabel text margin

Most suggestions are doing it with codes.

I did mine with some thing like this:

[myLabel setFrame:CGRectMake(75 ,20,size.width + 5,size.height+2)]; where size is the CGSize of my text content.

You can also try doing this with Auto Layout constraints.

Community
  • 1
  • 1
Andy
  • 5,287
  • 2
  • 41
  • 45
  • Thanks. There are certainly plenty of examples to accomplish this using code. I'm curious to know if anyone else has seen this change in UILabel behavior. – Rick Morgan Sep 25 '13 at 03:24
0

I used \a:

label.text = [NSString stringWithFormat: @"%@ \a", originalString];

That forces/tricks the space into showing.

lewis
  • 2,936
  • 2
  • 37
  • 72
-1

Yes, I've seen it and I'm not seeing a simple general fix for it!

Sam
  • 151
  • 8