简体   繁体   English

SwiftUI 带有 NavigationView 的屏幕背景颜色

[英]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).我正在尝试使用 NavigationView 将屏幕的背景颜色设置为相同颜色(浅灰色)。 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!更新:将颜色设置为 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()所以它甚至不是 UIView() 我需要的只是设置.ignoresSafeArea()

 Color.red.ignoresSafeArea()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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