Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has UILabel alignment behavior changed in xCode 5 / iOS 7?

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?

like image 302
Rick Morgan Avatar asked Sep 25 '13 00:09

Rick Morgan


2 Answers

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.

like image 155
lauriek334 Avatar answered Sep 17 '22 20:09

lauriek334


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.

like image 33
Andy Avatar answered Sep 17 '22 20:09

Andy