Skip to content

Style a navigation bar in SwiftUI - changing its background color, text color, style its status bar.

License

Notifications You must be signed in to change notification settings

globulus/swiftui-navigation-bar-styling

Repository files navigation

SwiftUINavigationBarStyling

Style a navigation bar in SwiftUI - changing its background color, text color, as well as styling the status bar. The end result looks like this:

in action

Recipe

Check out this recipe for in-depth description of the component and its code. Check out SwiftUIRecipes.com for more SwiftUI recipes!

Sample usage

Changing navigation bar background and text color:

var body: some View {
  NavigationView {
    VStack {
      Text("Hello World!")
    }.navigationBarColor(.blue, textColor: .white) // HERE
  }
}

Changing status bar style - in your SceneDelegate.swift, replace UIHostingController with StyledHostingController:

if let windowScene = scene as? UIWindowScene {
  let window = UIWindow(windowScene: windowScene)
  window.rootViewController = StyledHostingController(statusBarStyle: .lightContent, rootView: contentView) // HERE
  self.window = window
  window.makeKeyAndVisible()
}

Installation

This component is distrubuted as a Swift package.

About

Style a navigation bar in SwiftUI - changing its background color, text color, style its status bar.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages