如何在 SwiftUI 中删除 List 和 ScrollView 的底部填充 [英] How to remove bottom padding of List and ScrollView in SwiftUI

查看:52
本文介绍了如何在 SwiftUI 中删除 List 和 ScrollView 的底部填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除底部填充,即红色空间之间的空白.有什么办法可以实现吗?

I'd like to remove bottom padding, the white space between the red space. Is there any way to achieve it?

测试代码:

struct ContentView: View {
    var body: some View {
        return NavigationView {
            VStack {
                // the same result with using List instead of ScrollView
                ScrollView {
                    ForEach(1..<100) { index in
                        HStack {
                            Spacer()
                            Text("\(index)")
                            Spacer()
                        }
                    }
                }.background(Color.red)
                HStack {
                    Spacer()
                    Text("Test")
                    Spacer()
                }
                .background(Color.red)
            }
            .navigationBarTitle(Text("Test"), displayMode: .inline)
        }
    }
}

推荐答案

你必须传递 0 才能没有空格.默认情况下,它根据上下文使用默认空间

You have to pass 0 for no spacing. By default it takes default space based on context

VStack(spacing: 0) {

   // the same result with using List instead of ScrollView
   ScrollView {

   .........
}

这篇关于如何在 SwiftUI 中删除 List 和 ScrollView 的底部填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆