Navigation View Background Color

Hello. I have Navigation View with a List and 2 cells like this:

NavigationView {
            List{
                NavigationLink(destination: TabScene()) {
                // Cella 1
                 HStack {
                     Image(title[0].icon)
                     Text(title[0].title).font(.system(size: 30))
                 }
                }
                // Cella 2
                HStack {
                        Image(title[1].icon)
                        Text(title[1].title).font(.system(size: 30))
                    
                } // Con la tap sulla cella si attiva la State var a true
                .onTapGesture {
                    self.showTabView.toggle()
                } // Quando la state var va a true si presenta la scena desiderata.
                .sheet(isPresented: $showTabView, content: {
                    CreditsView()
                })
            }
                 .navigationBarTitle("ARPlanets 2")
                 .navigationViewStyle(DefaultNavigationViewStyle())
                 .listStyle(GroupedListStyle())
            }


Currently the background is white and it becomes black with the dark mode. Anyway i want to choose a custom background Color for my app.


How can i do that? So far i could not set a background Color for the Navigation View with a List embed inside it.

Replies

Did you read this ?

https://stackoverflow.com/questions/56923397/how-change-background-color-if-using-navigationview-in-swiftui


They propose some workarounds to do it.

They suggest to use

UIView.appearance().backgroundColor = UIColor.red

Where should i put this line of code?

What they suggest is to


Just add this to the initializer of your code

UIScrollView.appearance().backgroundColor = UIColor.red
.


Unfortunately, I cannot test presently.

Better answer than the one linked above is here: https://stackoverflow.com/questions/56505528/swiftui-update-navigation-bar-title-color


Basically, just create a dummy UIViewControllerRepresentable and use that UIViewController's navigationController property to configure the bar how you like.