4

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

Visual Sharp
  • 3,093
  • 1
  • 18
  • 29
  • Does this answer your question? [SwiftUI update navigation bar title color](https://stackoverflow.com/questions/56505528/swiftui-update-navigation-bar-title-color) – lorem ipsum Mar 21 '21 at 01:11

2 Answers2

4

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

ios coder
  • 1
  • 4
  • 31
  • 91
0

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

 Color.red.ignoresSafeArea()
Visual Sharp
  • 3,093
  • 1
  • 18
  • 29
  • 1
    thanks, I update the answer, at past we should use **UIView** as well but I think apple just done some update that we do not need it any more. – ios coder Mar 21 '21 at 12:39