xcode 中 uicontrol 的镜像编程

Mirror programming for uicontrols in xcode

我是多语言应用程序的新手。 我正在做的是, 具有两种语言的应用程序。 英语和阿拉伯语

应用程序的语言取决于设备语言。 (我也想改变这一点,应用程序语言应该从应用程序内部控制。不依赖于设备但这是下一个问题)

我有一些控件,例如 UIButtonUITextFieldUILabel 等....

当我的应用程序是英文时,我从设备的左角开始给这些控件框架,当我的应用程序是阿拉伯语时,我从设备的右角开始给它们框架。 (因为阿拉伯语是从右到左书写的)

我的问题是, 为此,我需要做额外的工作, 即检查设备语言,然后设置控制框架。 在每个视图中,我可能有 "n" 个控件,并且在我看来,为两种语言的所有控件提供框架大小似乎不太好。

Xcode 本身有什么可用的东西可以用来做这个吗? 意味着我需要为默认语言(即英语)提供框架,如果我的设备语言更改为阿拉伯语,那么控件框架将自动从右到左镜像。

以下屏幕可能会提供一些想法。 (我对所有这些检查设备语言的控件使用了不同的框架)

接受任何帮助。

提前致谢。 对不起,如果问题已经被问到。但我什么也没找到。 如果有人找到,那么 link 欢迎 :)

来自Supporting Right-to-Left Languages

Your user interface should be mirrored when displaying right-to-left languages. If you use base internationalization and Auto Layout, most of the user interface will appear mirrored automatically for you. The text direction changes to right-to-left with the exception of phone numbers and country codes which are always left-to-right. Some views and controls in your user interface may not change direction automatically which you can fix programmatically.


您正在寻找的功能称为自动布局,它是几年前由 Apple 推出的。它将处理您需要的许多事情,但也有很多事情需要为您做。上面的指南将指导您完成必要的步骤。


更新 来自 iOS 9.0:

iOS 9 brings comprehensive support for right-to-left languages, which makes it easier for you to provide a flipped user interface. For example:

  • Standard UIKit controls automatically flip in a right-to-left context.
  • UIView defines semantic content attributes that let you specify how particular views should appear in a right-to-left context.
  • UIImage adds the imageFlippedForRightToLeftLayoutDirection method, which makes it easy to flip an image programmatically when appropriate. To learn more about providing a flipped user interface, see Supporting Right-to-Left Languages.