SwiftUI 设计背景图片问题

问题描述 投票:0回答:1

我想要屏幕背景图像,绿色应该位于屏幕顶部,但使用下面的代码,为什么中间带有文本和按钮的绿色区域我希望它位于屏幕顶部

代码:

struct AppointmentStep1: View {
@Environment(\.dismiss) var dismiss

var body: some View {
    ZStack {
        // Background image
        Image("home_bg")
            .resizable()
            .scaledToFill()
            .edgesIgnoringSafeArea(.all)
        VStack {
            HStack {
                Button  {
                    dismiss()
                } label: {
                    Image(systemName: "arrow.left")
                        .font(.system(size: 25))
                        .tint(.white)
                        .padding(.trailing, 6)
                }

                Text("Appointment")
                    .font(.calibriRegular(with: 20))
                    .foregroundStyle(.white)
                Spacer()
            }
            .padding(16)
        }
        .background(
            Color.appGreen2
                .ignoresSafeArea()
        )

       Spacer()
    }
}
}

o/p:如何将绿色视图移动到顶部

enter image description here

swift image swiftui background stackview
1个回答
0
投票

您可以简单地为ZStack设置

alignment
,默认为
.center

ZStack(alignment: .top) { 
    ...
}
© www.soinside.com 2019 - 2024. All rights reserved.