ios - 如何设置 ViewController 的语言而不是设备的语言?

标签 ios swift uiviewcontroller

我想设置我的 ViewController 的语言(所有字符串都必须以我的语言加载),但设备的语言可能不同。 并且可以是不同的文本方向 LTR 或 RTL。 我该怎么做?

例子: 设备语言:俄语

View Controller :英语

最佳答案

我对这种情况的处理方式如下

class Strings {

    static var sharedInstance: Strings = Strings()

    // MARK: Properties
    var name: String

    init(){
        switch /* your custom language */ {
        case /* english */:
            self.name = "name"
        }
        // you can add multiple choices here
        default:
            self.name = "russian name"
    }

}
  • 在风投中
class ViewController: UIViewController {

    // MARK: Properties

    // MARK: Lifecycle Methods
    override func viewDidLoad() {
        super.viewDidLoad()
        // add it here if the app don't have the option to change the language while running
        // Strings.sharedInstance = Strings()
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        // or add it here if the app does have the option to change the language while running
        Strings.sharedInstance = Strings()
    }

}

关于ios - 如何设置 ViewController 的语言而不是设备的语言?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57027054/

相关文章:

iphone - 如何替换NavigationController Stack中的viewController?

ios - 从 MonoTouch 中的 NSDate(或 DateTime)获取 NSDateComponents 实例

ios - 尝试使用 Alamofire 4 和 OAuth2 发出 POST 请求时出错 - Swift

ios - 关于 SQL 和 Swift 的建议和信息

ios - 导航栏项目未垂直居中

swift - 根据条件添加约束的奇怪行为

ios - 没有圆角的模态?

ios - 将 Collection View 复制到不同场景的最简单方法

ios - 根据 iOS 6 通讯录使用文档,第 22 条规则

ios - 如何使用 Moya pod 为请求设置超时?