首页 > 解决方案 > 删除列表上的额外间距

问题描述

我不知道如何使 swipeActions 具有黑暗视图的大小,我尝试在下方放置一个垫片或文本,它只会在一些空间中造成更大的混乱。什么是正确的解决方案?

如果不清楚,如果你注意到紫色方块比左边的大,我希望它们的大小相同。

在此处输入图像描述

List(someItems, id: \.self) { item in
    VStack {
        TheView()
    }
    .swipeActions(allowsFullSwipe: true) {     // Adds custom swipe actions
        Button {
            
        } label: {
            Label("Hide", systemImage: "eye.slash")
        }
        .tint(.accentColor)
    }
    .listRowBackground(Color(.red)) // Sets Row color or a custom color: .listRowBackground(Color("DarkBackground"))
    .listRowInsets(EdgeInsets())    // Removes extra padding space in rows
    .listRowSeparator(.hidden)      // Removed lines between items
    .cornerRadius(10)
    .shadow(radius: 2)
    .padding(.bottom)
}
.listStyle(PlainListStyle()) // Removes extra spaces around the whole List

底部的额外空间是因为.padding(.bottom),如果我删除它,尺寸是正确的,但是这些项目会全部靠近,我需要一些空间。

编辑:

这是我在上面使用的名为“TheView()”的视图,它并不多,我认为问题不存在。

var body: some View {
    VStack {
        HStack {
            HStack(alignment: .center) {
                SomeImage()
            }
            
            HStack(alignment: .top) {
                VStack {
                    HStack {

                        Text("sometext")
                            .foregroundColor(.primary)
                            .bold()
                        
                        Spacer()
                    }
                    
                    HStack {
                        Text(String(xyz!))
                            .font(.footnote)
                            .fontWeight(.light)
                        Spacer()
                    }
                }
                
                HStack {
                    Text("$515")
                        .font(.footnote)
                        .fontWeight(.light)
                }
            }
            
        }
        .padding(5)
        .padding(.horizontal, 3)
    }
    .background(LinearGradient(gradient: Gradient(colors: [Color("SomeColor")]), startPoint: .topLeading, endPoint: .bottomTrailing))
}

标签: swiftswiftui

解决方案


推荐阅读