SwiftUI:如何在列表中提供TableFooterView

SwiftUI:如何在列表中提供TableFooterView,swiftui,Swiftui,我想在我的列表中提供SwiftUI中的TableFooter视图,以显示应用程序的版权和版本 在UIKit中,我可以通过以下代码实现这一点: tableView.tableFooterView = SomeFooterView(frame: .init(x: .zero, y: .zero, width: UIScreen.main.bounds.width, height: 80)) 结果: 然而,在SwiftUI列表中,我只能在部分(页脚:)中实现这一点。我的另一种方法是: va

我想在我的列表中提供SwiftUI中的TableFooter视图,以显示应用程序的版权和版本

在UIKit中,我可以通过以下代码实现这一点:

tableView.tableFooterView = SomeFooterView(frame: .init(x: .zero, y: .zero, width: UIScreen.main.bounds.width, height: 80))
结果:

然而,在SwiftUI列表中,我只能在
部分(页脚:)
中实现这一点。我的另一种方法是:

    var body: some View {
        NavigationView {
            Group {
                VStack {
                    List {
                            
                       //Lists code...
                            
                    }
                        
                    Text("© 2021 - \(getCurrentYear())")
                    Text("Version \(getVersion() ?? "")")
                }
            }
            .listStyle(InsetGroupedListStyle())
            .navigationBarTitle("Settings")
        }
    }
但这是我取得的成果:

如何获得与
表中完全相同的结果。tableFooterView

部分(页脚:)
似乎是您应该使用的。。。我不知道您为什么不想使用它,但这是有效的:

struct ContentView: View {
    var body: some View {
        
        NavigationView {
            List {
                
                Text("Your list code")
                
                Section(
                    footer:
                        VStack {
                            Text("© 2021")
                            Text("Version 1.0.0")
                        }
                        .frame(maxWidth: .infinity)
                ) { EmptyView() } /// show nothing for the title
            }
            .listStyle(InsetGroupedListStyle())
            .navigationBarTitle("Settings")
        }
    }
}
结果:


但是如果您绝对不能使用
部分(页脚:)
,您可以直接将版权文本添加到
列表中。要摆脱默认样式,您需要使用以下组合:

  • listRowInsets(EdgeInsets())
    以除去插入
  • frame(maxWidth:.infinity,minHeight:60)
    使内容向外扩展(否则将很小)
  • .background(Color(UIColor.systemGroupedBackground))
    使背景与列表的背景匹配
  • 结果:


    等待
    部分(页脚:)
    有什么问题?
    
    struct ContentView: View {
        var body: some View {
            
            NavigationView {
                List {
                    Text("Just put it inside the List!")
                    
                    VStack {
                        Text("© 2021")
                        Text("Version 1.0.0")
                    }
                    .listRowInsets(EdgeInsets())
                    .frame(maxWidth: .infinity, minHeight: 60)
                    .background(Color(UIColor.systemGroupedBackground))
                }
                .listStyle(InsetGroupedListStyle())
                .navigationBarTitle("Settings")
            }
        }
    }