アプリ全体にNavigationItemの色を反映させる

アプリ全体に NavigationItemの色を反映させる iOS

アプリケーション全体のNavigationBarItemの色を変更したい場合は、AppDelegateに設定することで可能となります。

AppDelegate.swift
// ナビゲージョンアイテムの文字色
UINavigationBar.appearance().tintColor = UIColor.red
 
// ナビゲーションバーのタイトルの文字色
UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.blue]
 
// ナビゲーションバーの背景色
UINavigationBar.appearance().barTintColor = UIColor.yellow
 
// ナビゲーションバーの背景の透過
(UINavigationBar.appearance() as UINavigationBar).setBackgroundImage(UIImage(), for: .default)
 
// ナビゲーションバーの下の影を無くす
UINavigationBar.appearance().shadowImage = UIImage()

アプリケーション全体ではなく、個別にカスタマイズする場合はカスタマイズしたいViewControllerに指定することで可能となります。

カスタマイズしたいViewController
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    // ナビゲージョンアイテムの文字色
    self.navigationController!.navigationBar.tintColor = UIColor.red
    // ナビゲーションバーのタイトルの文字色
    self.navigationController!.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.blue]
    // ナビゲーションバーの背景色
    self.navigationController!.navigationBar.barTintColor = UIColor.yellow
    // ナビゲーションバーの背景の透過
    self.navigationController!.navigationBar.setBackgroundImage(UIImage(), for: .default)
    // ナビゲーションバーの下の影を無くす
    self.navigationController!.navigationBar.shadowImage = UIImage()
}

参考記事