我想设置我的 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/