简体   繁体   English

在 SwiftUI 中更改 NavigationView 的背景颜色

[英]Changing background color of NavigationView in SwiftUI

Is there a way to change the color of a NavigationView or to make it clear so the elements underneath are visible?有没有办法改变 NavigationView 的颜色或使其清晰,以便下面的元素可见?

struct SwiftUIView: View {
    var body: some View {
        
        ZStack {
            Color.red.edgesIgnoringSafeArea(.all) //not visible beacause of NavigationView
            
            NavigationView {
                Text("Hello, World!")
            }.background(Color.clear) //this does nothing
        }
        
    }
}

I would do this:我会这样做:

struct SwiftUIView: View {
var body: some View {
   NavigationView {
        ZStack{
            Color.red.edgesIgnoringSafeArea(.all)
            Text("Hello, World!")
        }
   }
}
}

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

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