我一直在尝试以下方法,以使导航栏的标题保持左对齐:
在AppDelegate.swift文件中:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UINavigationBar.appearance().barTintColor = UIColor.red
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:
UIColor.white]
return true
}
Run Code Online (Sandbox Code Playgroud)
在TableViewController.swift文件中:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.navigationController?.navigationBar.topItem?.title = "Home"
}
Run Code Online (Sandbox Code Playgroud)
但我找不到任何解决问题的方法.我还尝试了以下我在这里找不到的内容:
在AppDelegate.swift文件中:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UINavigationBar.appearance().barTintColor = UIColor.red
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:
UIColor.white]
let lbNavTitle = …Run Code Online (Sandbox Code Playgroud)