最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

iOS 让界面元素的文字随着语言的更改而变化——本地化文字跟随

维修 admin 77浏览 0评论

iOS 让界面元素的文字随着语言的更改而变化——本地化文字跟随

在我的 App 内置的设置中,修改了语言,这时需要让当前界面的文本跟着改变语言。

解决方法是:添加一个观察者,观察 localize 本地语言的通知,然后一有变化就调用自定义的方法执行操作。(而设置中其实是改变了 localize 的语言)

override func viewDidLoad() {tableForChoose = tableChoosesuper.viewDidLoad()NotificationCenter.default.addObserver(self, selector: #selector(setText), name: NSNotification.Name(LCLLanguageChangeNotification), object: nil)
}
@objc func setText() {btn_complete?.setTitle("done".localized(), for: .normal)tableForChoose?.reloadData()tableForChoose?.selectRow(at: defaultChoose ?? IndexPath(row: 0, section: 0), animated: true, scrollPosition: .middle)if let cell = tableForChoose?.cellForRow(at: defaultChoose ?? IndexPath(row: 0, section: 0)) {cell.accessoryType = .checkmark}
}

iOS 让界面元素的文字随着语言的更改而变化——本地化文字跟随

在我的 App 内置的设置中,修改了语言,这时需要让当前界面的文本跟着改变语言。

解决方法是:添加一个观察者,观察 localize 本地语言的通知,然后一有变化就调用自定义的方法执行操作。(而设置中其实是改变了 localize 的语言)

override func viewDidLoad() {tableForChoose = tableChoosesuper.viewDidLoad()NotificationCenter.default.addObserver(self, selector: #selector(setText), name: NSNotification.Name(LCLLanguageChangeNotification), object: nil)
}
@objc func setText() {btn_complete?.setTitle("done".localized(), for: .normal)tableForChoose?.reloadData()tableForChoose?.selectRow(at: defaultChoose ?? IndexPath(row: 0, section: 0), animated: true, scrollPosition: .middle)if let cell = tableForChoose?.cellForRow(at: defaultChoose ?? IndexPath(row: 0, section: 0)) {cell.accessoryType = .checkmark}
}

发布评论

评论列表 (0)

  1. 暂无评论