我為需要在其他類中呼叫的結構制作了一個檔案,但我正在盡一切努力使其作業,但似乎我不會獨自完成并弄清楚。
單個檔案的代碼:
import Foundation
struct CustomLanguage {
func createBundlePath () -> Bundle {
let selectedLanguage = "en"
let path = Bundle.main.path(forResource: selectedLanguage, ofType: "lproj")
return Bundle(path: path!)!
}
}
其他類:
import Foundation
import UIKit
class signInViewController: UIViewController {
@IBOutlet weak var welcomeLabelSignIn: UILabel!
override func viewDidLoad() {
welcomeLabelSignIn.text = NSLocalizedString("Welcome!", tableName: nil, bundle: "the structure call here" , value: "", comment: "")
}
所以在捆綁包中:我需要呼叫該結構
結構的單個檔案
我不能呼叫它來本地化其他類中的標簽、按鈕……
uj5u.com熱心網友回復:
試試這個;
struct CustomLanguage {
static func createBundlePath () -> Bundle {
let selectedLanguage = "en"
let path = Bundle.main.path(forResource: selectedLanguage, ofType: "lproj")
return Bundle(path: path!)!
}
}
然后;
welcomeLabelSignIn.text = NSLocalizedString("Welcome!", tableName: nil, bundle: CustomLanguage.createBundlePath() , value: "", comment: "")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/457887.html
