Skip to content

Instantly share code, notes, and snippets.

@nickmeehan
Created November 3, 2018 19:17
Show Gist options
  • Save nickmeehan/805d656357ca17c6231b7f981cb9e3e6 to your computer and use it in GitHub Desktop.
Save nickmeehan/805d656357ca17c6231b7f981cb9e3e6 to your computer and use it in GitHub Desktop.
Setting Navigation Bar Colour
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Any other set-up code you need.
// This allows us to access the navigation bar since .appearance returns the proxy for the receiver,
// our UINavigationBar.
let navigationBarAppearace = UINavigationBar.appearance()
// This colour applies to the navigation items and bar button items.
navigationBarAppearace.tintColor = .blue
// This colour applies to the navigation bar background.
navigationBarAppearace.barTintColor = .white
// This is THE big one. This indicates whether the bar background is translucent or not.
// By indicating false here, we are able to ensure the barTintColor assigned above is
// the full colour we intend.
navigationBarAppearace.isTranslucent = false
// This colour applies to the title of the view controller pushed into the stack.
navigationBarAppearace.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.blue]
// Override point for customization after application launch.
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment