[英]How to Make NavigationView Background Transparent SwiftUI
I already searched, but can't find a solution that works.我已经搜索过,但找不到有效的解决方案。
I have this super simple code.我有这个超级简单的代码。 When I add the NavigationView, the background color goes away.
当我添加 NavigationView 时,背景颜色会消失。
I think if I can make the background color of NavigationView Transparent, it would solve the issue.我想如果我可以让 NavigationView 的背景颜色透明,它会解决这个问题。
struct TestView: View {
var body: some View {
VStack {
Spacer()
NavigationView {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
}
Spacer()
}
.background(Color(red: 128 / 255, green: 27 / 255, blue: 44 / 255))
.ignoresSafeArea(.all)
}
}
Thanks in advance提前致谢
I had the exact same issue.我有完全相同的问题。 I managed to solve this by keeping the 'NavigationView' as the parent and having the ZStack as the child for your background
我设法通过将“NavigationView”保持为父级并将 ZStack 作为您的背景的子级来解决此问题
So to take your code:所以拿你的代码:
var body: some View {
Spacer()
NavigationView {
ZStack {
//Your colour here + Safezone ignore
}
VStack {
Text("Hello, World!")
Spacer()
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.