首页 > 解决方案 > UIButton semanticContentAttribute 属性在 Localization 中被强制 RTL

问题描述

我正在开发一个支持两种语言(英语和阿拉伯语)的应用程序。我有一个loginCViewController,我有一个UIButton and UITextField。当我切换到 时Arabic,我UIButton semanticContentAttribute是被迫的RightToLeft,这是我不想要的。

Arabic

在此处输入图像描述

English

在此处输入图像描述

这是我到目前为止所尝试的,但是semanticContentAttribute当切换到阿拉伯语时,我的 UIButton 仍然从 RightToLeft 更改。

我希望我loginViewController的两种语言看起来都一样。

override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        numberButton.semanticContentAttribute = .forceLeftToRight
    }

我什至试过了,viewDidLayoutSubviews()但结果还是一样。

override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        numberButton.semanticContentAttribute = .forceLeftToRight
    }

对此的任何帮助将不胜感激。

标签: swiftlocalizationarabic

解决方案


嘿,也许这段代码会对你有所帮助,因为它对我有用。

   UIView.appearance().semanticContentAttribute = .forceLeftToRight
   let window = self.view.superview
   self.view.removeFromSuperview()
   window?.addSubview(self.view)

推荐阅读