简体   繁体   English

SwiftUI 列表中神秘的前导/尾随填充?

[英]SwiftUI mysterious leading/trailing padding in List?

Inside my SwiftUI List view are scrollable posts that have a mysterious leading & trailing padding that I cannot figure out where is coming from?在我的 SwiftUI 列表视图中有可滚动的帖子,它们有一个神秘的前导和尾随填充,我无法弄清楚它来自哪里? (See image encircled in blue) (见蓝色圈出的图片)

I want the post images to extend all the way to the edges of the phone screen so there is no white-space at all.我希望帖子图像一直延伸到手机屏幕的边缘,所以根本没有空白。

I put a background Color of red on my PostCell, and as you can see in the image, the padding doesn't appear to be coming from the PostCell because you see the leading/trailing white padding on either side of it.我在我的 PostCell 上放置了红色的背景颜色,正如您在图像中看到的那样,填充似乎不是来自 PostCell,因为您在它的任一侧看到了前导/尾随的白色填充。

Below is my complete view hierarchy as is in my app and there is no padding, which seems to be about 30 points, anywhere in the hierarchy.下面是我的应用程序中的完整视图层次结构,层次结构中的任何位置都没有填充,这似乎是大约 30 点。

I am assuming this padding is being applied by default somewhere??我假设默认情况下在某处应用此填充?

Any ideas on how to get rid of this padding?关于如何摆脱这种填充的任何想法?

在此处输入图像描述

ROOT VIEW根视图

struct RootView: View {
    var body: some View {
        TabView {
            // OTHER VIEW
            // OTHER VIEW
            // OTHER VIEW
            // OTHER VIEW
            ProfileView(profileVM: ProfileViewModel())
        }
    }
}

PARENT VIEW父视图

struct ProfileView: View {
    @StateObject var profileVM: ProfileViewModel
    @State private var presentSettings: Bool = false

    var body: some View {
        NavigationView {
                List {
                    ProfileContent(profileVM: profileVM)
                }
                .clipped()
                .listStyle(PlainListStyle())
                .refreshable {
                    Task.detached { await profileVM.loadData() }
                }
                .navigationViewStyle(StackNavigationViewStyle())
                .navigationBarTitle(Text(""), displayMode: .inline)
                .background (
                    NavigationLink("", destination: ListView(profileVM: profileVM), isActive: $profileVM.presentPostView).isDetailLink(false)
                )
        }
    }
}

CHILD VIEW儿童视角

struct ListView: View {
    @Environment(\.presentationMode) var presentation
    @ObservedObject var profileVM: ProfileViewModel
        
    var body: some View {
        ScrollViewReader { proxy in
            List(profileVM.usersPosts, id: \.id) { post in
                PostCell(post: post)
                    .background(Color.red)
            }
            .clipped()
            .listStyle(PlainListStyle()) 
            .navigationViewStyle(StackNavigationViewStyle())
            .navigationBarTitle(Text("your posts"), displayMode: .inline)
            .navigationBarBackButtonHidden(true)
            .toolbar(content: {
                ToolbarItem(placement: .navigationBarLeading) {
                    ZStack {
                        Button(action: {print("action")}, label: {Text("Press")})
                    }.padding(.leading, 10)
                }
            })
        } 
    }
}

I assume you need to zero list row insets我假设您需要将行插图归零

PostCell(post: post)
    .background(Color.red)
    .listRowInsets(EdgeInsets())   // << here !!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM