简体   繁体   中英

SwiftUI background color of the screen with NavigationView

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"))
        }
        
    }

在此处输入图像描述

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"))
        }
        
    }
}

在此处输入图像描述

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

 Color.red.ignoresSafeArea()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM