自动版式+ RTL +的UILabel文本对齐 [英] AutoLayout + RTL + UILabel text alignment

查看:442
本文介绍了自动版式+ RTL +的UILabel文本对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我终于变圆了与自动布局摔跤,似乎无法弄清楚如何让从右到左(RTL)的支持工作,我所希望的方式/想...

I'm finally getting round to wrestling with Auto Layout and can't seem to figure out how to get right-to-left (RTL) support to work the way I'd expect/want...

我已经设计在Interface Builder视图,如图所示:

I have designed the view in Interface Builder as shown:

通过生成的应用程序正在按预期运行使用英语时:

With the resulting app running as expected when using English:

但是切换到RTL语言(阿拉伯语在这种情况下)时,整个视图翻转(这是伟大的),但的UILabel 的文本仍然左对齐。我希望它是正确对齐,以保持它反对的UIImageView

However when switching to an RTL language (Arabic in this case), the entire view flips (which is great) but the UILabel's text is still left aligned. I'd expect it to be right aligned to keep it up against the UIImageView.

显然我想的东西和/或本不覆盖的自动布局。

Clearly I'm missing something and/or this isn't covered by Auto Layout.

我应该使用RTL语言时, textAlignment 手动设置?

Am I supposed to set the textAlignment manually when using an RTL language?

推荐答案

您想 NSTextAlignmentNatural 。这推断从加载的应用程序语言文字的对齐方式(不是从剧本)。

You want NSTextAlignmentNatural. That infers the text alignment from the loaded application language (not from the script).

对于iOS 9及更高版本(使用X code 7),你可以在故事板设置此(选择---对齐选项)。如果您需要针对早期版本中,你需要创建一个出口标签,并设置在 awakeFromNib 对齐。

For iOS 9 and later (using Xcode 7), you can set this in the storyboard (choose the --- alignment option). If you need to target earlier releases, you'll need to create an outlet to the label and set the alignment in awakeFromNib.

- (void)awakeFromNib {
    [[self label] setTextAlignment:NSTextAlignmentNatural];
}

这篇关于自动版式+ RTL +的UILabel文本对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆