如何在 iOS 上更改導航欄文字顏色?
更改導航欄文字顏色既簡單又棘手,在這篇文章中,我們將介紹如何使用 swift 更改導航欄的文字顏色。
那麼讓我們開始吧,
如下圖所示,將檢視控制器嵌入導航控制器中,並將特定控制器的導航專案命名為教程,如下圖所示,
現在導航到 AppDelegate.swift 並向 didFinisheLaunchingWithOptions 方法中新增以下行。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. let textColor = [NSAttributedString.Key.foregroundColor:UIColor.green] UINavigationBar.appearance().titleTextAttributes = textColor return true }
執行應用程式,看看我們如何將顏色更改為綠色。
廣告