Member-only story
How to change navigation bar color — SwiftUI Tips
With iOS 16, Apple released new toolbar APIs, which includes new features for navigation bars. To change the background color of a navigation bar, we can simply use the toolbarBackground
modifier.
For example, we can create a simple list that shows a colored navigation bar like so:
We use Color.mint
as the style and navigationBar
as the toolbar that this style should apply to. In some cases, the navigation bar background is not initially visible, for example, in a list you might need to scroll first for the background to appear. This is why we also set the toolbar’s background to .visible
, but this could vary based on the style behavior you desire.
Thanks for reading, I hope you found this tip helpful! Make sure to follow me if you want to continue learning about iOS app development with SwiftUI and be notified when I publish a new story.