vstack全屏背景图像

我希望有一个带有导航视图的全屏背景图像(必须在最上面,因为它是从基本视图而不是通常在“此”视图中)。 在此视图中,我想要一个VStack,它位于安全区域之内,因此位于导航栏和底部布局之间。

不幸的是我得到了(见图)

我希望里面的文本...

vstack全屏背景图像

struct ContentView: View {
    var body: some View {
        NavigationView {
            ZStack(alignment: .center) {

                Image("laguna")
                    .resizable()
                    .edgesIgnoringSafeArea(.all)
                    .scaledToFill()
                    .frame(width: UIScreen.main.bounds.width,height: UIScreen.main.bounds.height)

                VStack(alignment: .center) {
                    Text("just a test")
                        .font(.largeTitle)
                        .foregroundColor(Color.white)
                    Spacer()
                    Text ("not centered....why?")
                        .font(.largeTitle)
                        .foregroundColor(Color.white)

                }
                .zIndex(4)
                .navigationBarTitle("nav bar title")
            }
        }
    }
}
chenhui1646 回答:vstack全屏背景图像

这是一个经过修改的变体。经过Xcode 11.4(最终发布)/ iOS 13.4的测试

demo

struct TestFullScreenImage: View {
    var body: some View {
        NavigationView {
            ZStack {
                Image("large_image")
                    .resizable()
                    .edgesIgnoringSafeArea(.all)
                    .scaledToFill()

                VStack {
                    Text("Just a test")
                        .font(.largeTitle)
                        .foregroundColor(.white)
                        Spacer()
                    Text("centered")
                        .font(.largeTitle)
                        .background(Color.green)
                }
                .navigationBarTitle("Navigation Title")
            }
        }
        .frame(maxWidth: .infinity,maxHeight: .infinity)
    }
}
本文链接:https://www.f2er.com/2581729.html

大家都在问