小编Sha*_*rde的帖子

如何在Xcode中左对齐导航栏的标题?

我一直在尝试以下方法,以使导航栏的标题保持左对齐:

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)

xcode uinavigationbar swift

10
推荐指数
4
解决办法
1万
查看次数

标签 统计

swift ×1

uinavigationbar ×1

xcode ×1