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

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

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

swift 复制代码
override func viewDidLoad() {
        tableForChoose = tableChoose
        super.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
        }
}
 
相关推荐
Wcowin32 分钟前
OneClip 开发经验分享:从零到一的 macOS 剪切板应用开发
mac·swift·粘贴板
如此风景4 小时前
iOS SwiftUI开发所有修饰符使用详解
ios
mumuWorld4 小时前
KSCrash 实现机制深度分析
ios·源码阅读
AskHarries5 小时前
Google 登录问题排查指南
flutter·ios·app
崽崽长肉肉6 小时前
Swift中的知识点总结
ios·swift
2501_916007477 小时前
苹果手机iOS应用管理全指南与隐藏功能详解
android·ios·智能手机·小程序·uni-app·iphone·webview
代码不行的搬运工9 小时前
面向RDMA网络的Swift协议
开发语言·网络·swift
2501_9151063210 小时前
全面理解 iOS 帧率,构建从渲染到系统行为的多工具协同流畅度分析体系
android·ios·小程序·https·uni-app·iphone·webview
TouchWorld11 小时前
iOS逆向-哔哩哔哩增加3倍速(1)-最大播放速度
ios·逆向
RollingPin11 小时前
React Native与Flutter的对比
android·flutter·react native·ios·js·移动端·跨平台开发