SwiftUI background color of the screen with NavigationView

Viewed 977

I'm trying to set background color of a screen with NavigationView to be of the same color (light gray). My aim is to have the background color of every screen and navigation view background to be the same (gray) globally. How would I archive it? I've tried this:

 var body: some View {

        NavigationView {
            ZStack {
                Color.gray.opacity(0.1)
                VStack{
                    
                 Spacer()
                }
            }.navigationTitle("Today")
           
            .navigationBarItems(leading: Text("some texts"))
        }
        
    }

enter image description here

2 Answers

Updated: with putting Color as ignoresSafeArea!


import SwiftUI

struct ContentView: View {
    
    var body: some View {
        
        NavigationView {
            
            ZStack {
                
                Color
                    .red
                    .ignoresSafeArea()     // <<: Here
                
                Color
                    .yellow
                    .cornerRadius(20)
                    .padding()
                
                
            }.navigationTitle("Today")
            
            .navigationBarItems(leading: Text("some texts"))
        }
        
    }
}

enter image description here

So it wasn't even UIView() All I need was to set .ignoresSafeArea()

 Color.red.ignoresSafeArea()
Related