AutoLayout + RTL + UILabel 文本对齐

AutoLayout + RTL + UILabel text alignment(AutoLayout + RTL + UILabel 文本对齐)
本文介绍了AutoLayout + 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.这会从加载的应用程序语言(not 来自脚本)推断文本对齐方式.

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

对于 iOS 9 及更高版本(使用 Xcode 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];
}

这篇关于AutoLayout + RTL + UILabel 文本对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)