首页 > 解决方案 > SwiftUI 将 vstack 推送到屏幕的剩余长度

问题描述

我目前有一个产品页面视图,但我遇到了一些问题。我的目标是将灰褐色推到屏幕底部。我尝试过使用 Spacer(),并在其中包含 Spacer() 的 VStack 下添加一个 VStack,但它没有推到屏幕底部。我怎样才能做到这一点?

在此处输入图像描述

ZStack {
            Color.white
           ScrollView  {
                VStack {
                    KFImage(URL(string: bottle?.image ?? "Test"))
                        .resizable()
                        .frame(width: 200, height: 300)
                        .padding([.top], 50)
                }
                .padding([.bottom], 40)
            
                VStack(alignment: .leading) {
                    HStack {
                        Text(bottle?.name ?? "Test")
                            .font(.title2)
                            .fontWeight(.semibold)
                        Spacer()
                        SpiritTag(spirit: bottle?.varietal ?? "Other")
                    }
                    if((bottle?.brand_id) != nil) {
                        NavigationLink(destination: BrandView(brandId: bottle?.brand_id ?? "1")) {
                            HStack {
                                KFImage(URL(string: brand?.logo ?? "Test"))
                                 .resizable()
                                .frame(width: 48, height: 48)
                                    .cornerRadius(10)
                                VStack(alignment: .leading) {
                                    Text("\(brand?.name ?? "Unknown")")
                                        .fontWeight(.bold)
                                    Text("\(brand?.bottle_count ?? 0) bottles")
                                        .font(.caption)
                                }
                            }
                        }
                    }
                    
                    HStack {
                        Button(action: {
                          self.show_modal = true
                        }) {
                            Text("Add to list")
                        }
                        .frame(height: 15)
                        .frame(maxWidth: .infinity)
                        .padding()
                        .background(Color("Onyx"))
                        .foregroundColor(Color.white)
                        .cornerRadius(10)
                        .sheet(isPresented: self.$show_modal) {
                            CollectionAddition(userId: session.auth.currentUser!.uid, bottleId: bottle!.id)
                        }
                    }
                    VStack(alignment: .leading) {
                        Text("Information")
                            .font(.title3)
                            .fontWeight(.semibold).padding([.bottom], 1)
                        Text(bottle?.information ?? "")
                            .fixedSize(horizontal: false, vertical: true)
                    }.padding([.bottom])
                }
                .padding()
                .padding(.top)
                .background(Color("Tope"))
                .cornerRadius(30, corners: [.topLeft, .topRight])
                .offset(x: 0, y: -30.0)
           }
           .edgesIgnoringSafeArea(.top)
        }

标签: iosswiftswiftui

解决方案


推荐阅读