Search code examples
iosswiftswiftuinavigationbar

How to force navigation bar to show background in SwiftUI?


I have the following (on iOS 16):

NavigationStack
{
    Form
    {
        ....
    }
}
.navigationTitle("Hello")
.navigationBarTitleDisplayMode(.inline)

The navigation bar background only appears when scrolling the Form upwards.

How can I make sure that the background is always showing?


Solution

  • use this to always show the background:

    .toolbarBackground(.visible, for: .navigationBar)
    

    and this to style it:

    .toolbarBackground(.red, for: .navigationBar)