https://github.com/globulus/swiftui-navigation-bar-styling
Style a navigation bar in SwiftUI - changing its background color, text color, style its status bar.
https://github.com/globulus/swiftui-navigation-bar-styling
Last synced: about 1 month ago
JSON representation
Style a navigation bar in SwiftUI - changing its background color, text color, style its status bar.
- Host: GitHub
- URL: https://github.com/globulus/swiftui-navigation-bar-styling
- Owner: globulus
- License: mit
- Created: 2021-05-24T06:11:05.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2022-02-27T20:09:15.000Z (about 4 years ago)
- Last Synced: 2025-04-24T13:34:50.017Z (11 months ago)
- Language: Swift
- Size: 5.86 KB
- Stars: 8
- Watchers: 5
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:

### Recipe
Check out [this recipe](https://swiftuirecipes.com/blog/navigation-bar-styling-in-swiftui) for in-depth description of the component and its code. Check out [SwiftUIRecipes.com](https://swiftuirecipes.com) for more **SwiftUI recipes**!
### Sample usage
Changing navigation bar background and text color:
```swift
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`:
```swift
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**.