以编程方式从右到左RTL更改 [英] Changing to right to left RTL programmatically

查看:87
本文介绍了以编程方式从右到左RTL更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个支持两种语言的应用程序:英语和阿拉伯语. 当用户将语言更改为阿拉伯语时,我需要我的应用程序才能使文本从右到左(RTL).

I'm working on an App which supports two languages: English and Arabic. When the user changes the language to Arabic, I need my app to make the text right-to-left (RTL).

我搜索了此问题,发现关于支持RTL的答案.

I searched for this issue, and I found this answer about supporting RTL.

我想以编程方式应用上述答案,因为我需要在应用运行时从LTR更改为RTL.

I would like to do apply the the above answer but in a programmatically way, because I need to change from LTR to RTL while the App is running.

推荐答案

我使用以下方法将我的应用程序从右到左RTL更改为:

I changed my app to right to left RTL by using this :

self.transform = CGAffineTransformMakeScale(-1.0, 1.0)

这会翻转视图,然后我像这样翻转视图中的对象:

This flipped the view, then i flipped the objects in the view like this:

label.transform = CGAffineTransformMakeScale(-1.0, 1.0)
textField.transform = CGAffineTransformMakeScale(-1.0, 1.0)
image.transform = CGAffineTransformMakeScale(-1.0, 1.0)

这使我的视图成为RTL,而不是更改所有约束或将应用重建为RTL.

This made my views RTL instead of changing all constraints or rebuild the app as RTL.

这篇关于以编程方式从右到左RTL更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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