How can I change the background Color of a navigation view?

I'm currently creating the sidebar for my app and now I am facing the problem of how I can change the background Color of my navigation view without affecting the background of the other views.
I've tried it like this:
Code Block
init(){
UITableView.appearance().backgroundColor = UIColor.secondarySystemBackground
}

That works but now all of my list backgrounds have this color, which a don't want.


And if I try it like this, it doesn't change at all:
Code Block  
ZStack{
    Color.red
    List{
        VStack{
            NavigationLink(destination: ColorMenu()){
                Label("Colors", systemImage: "square.grid.2x2.fill").accentColor(Color("Colory"))
            }
        }
    }
}

So my question is if there is a way to change the background Color without affecting all the other views?

Thanks in advance



Answered by Claude31 in 710101022

Old question, but, in case.

Declare a Stack at the top, and set the color of the ZStack.

    var body: some View {

        NavigationView {
            ZStack {
                Color.purple
                    .ignoresSafeArea()
                // Usual content
            }
    }
Take a look at this answer.
Thanks for your reply.
I tried that but that changes the background in every view that has a list in it. and I only want it in one view.

Are there any updates or solutions to this problem. I am using iOS 15 and have not found a true solution to this problem

Accepted Answer

Old question, but, in case.

Declare a Stack at the top, and set the color of the ZStack.

    var body: some View {

        NavigationView {
            ZStack {
                Color.purple
                    .ignoresSafeArea()
                // Usual content
            }
    }
How can I change the background Color of a navigation view?
 
 
Q