2021年4月2日星期五

SwiftUI Content View random padding

I am currently creating a content view for my application and am experiencing some strange behavior with padding. As seen in the photo below, there is quite a bit of space below the navigation bar at the top of the phone. I don't specify any padding here so I'm wondering why there is so much space between the top and where the image is displayed. The image doesn't have that large of a white box around it either.

My code does not specify any kind of margin or padding. I'm new to Swift and SwiftUI so I'm curious if there is some automatic padding applied to navigation views?

import Kingfisher    struct BottleView: View {      let bottle: Bottle        var body: some View {          VStack {              KFImage(URL(string: bottle.image ?? "")!)               .resizable()              .frame(width: 128, height: 256)                VStack(alignment: .leading) {                  HStack {                      Text(bottle.name)                          .font(.title)                      Spacer()                      Text("Price")                  }                    HStack {                      Text(bottle.varietal ?? "")                      Spacer()                      Text("$\(bottle.price ?? "")")                  }                  .font(.subheadline)                  .foregroundColor(.secondary)                    VStack(alignment: .leading) {                      Text("Information")                          .font(.title2)                      Text(bottle.information ?? "")                  }              }          }      }  }  
Image with text underneath, but everything is centered in the screen https://stackoverflow.com/questions/66927512/swiftui-content-view-random-padding April 03, 2021 at 11:38AM

没有评论:

发表评论