Xcode5 and iOS7: trailing whitespaces in strings in Localizable.strings not working anymore

流过昼夜 提交于 2019-12-04 01:21:06

问题


In my Localizable.strings I define a string with trailing whitespaces like this:

"%@ points  " = "%@ Punkte  ";

This worked just fine in iOS6 but when runing on an iOS7 emulator, the string is trimmed and the trailing whitespaces are stripped off.

Background: The string above is right-aligned in a label. I use the whitespaces as a padding since I dont want to subclass UILabel or write a bunch of code for just one label.

I also tried using ASCII signs, but this also did not work.

Any suggestions for a simple soultion would be appreciated.

Thank you!


回答1:


Perhaps you can try this workaround with NSMutableAttributedString which worked for me. The "." is put in place of the whitespace.

NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%i.", count]];


 [string addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0,string.length-1)];

 [string addAttribute:NSForegroundColorAttributeName value:[UIColor clearColor] range:NSMakeRange(string.length-1,1)];



回答2:


Have you tried the non breaking space character?




回答3:


Ok, I am solving this issue by adding the label as a subview to a view and setting the width of the label a bit smaller that that of the view.

All styling, i.e. background image, animations etc. is done to the view, not the label. Not the KISS principle but it works.

Thanks anyway.



来源:https://stackoverflow.com/questions/18914838/xcode5-and-ios7-trailing-whitespaces-in-strings-in-localizable-strings-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!