【发布时间】:2021-02-11 15:19:36
【问题描述】:
我正在尝试在 List 的底部添加一个视图,同时保持在安全区域中。这就是我想要结束的,我指的是“更新时间:上午 5:26”:
我尝试使用带有分隔符的Section 页脚,但这不起作用:
struct ContentView: View {
@State private var selectedTab = 0
var body: some View {
TabView(selection: $selectedTab) {
List {
Section {
Text("Item 1")
Text("Item 1")
Text("Item 1")
}
Section(
footer: VStack {
Spacer()
Text("Updated at: 5:26 AM")
.frame(maxWidth: .infinity)
}
) {
Text("Item 1")
Text("Item 1")
Text("Item 1")
}
}
.listStyle(InsetGroupedListStyle())
.tabItem {
Label("First", systemImage: "alarm")
}
Text("Content 2")
.tabItem {
Label("Second", systemImage: "calendar")
}
}
}
}
然后我尝试了一个 VStack 作为它自己的一部分和一个 Spacer 但也没有运气:
struct ContentView: View {
@State private var selectedTab = 0
var body: some View {
TabView(selection: $selectedTab) {
List {
Section {
Text("Item 1")
Text("Item 1")
Text("Item 1")
}
Section {
Text("Item 1")
Text("Item 1")
Text("Item 1")
}
VStack {
Spacer()
Text("Updated at: 5:26 AM")
.font(.footnote)
.foregroundColor(.secondary)
.frame(maxWidth: .infinity)
}
.listRowBackground(Color(.systemGroupedBackground))
}
.listStyle(InsetGroupedListStyle())
.tabItem {
Label("First", systemImage: "alarm")
}
Text("Content 2")
.tabItem {
Label("Second", systemImage: "calendar")
}
}
}
}
如何在考虑List 可能滚动的同时实现这一目标?我正在尝试将其添加到列表的末尾,而不是浮动。
【问题讨论】:
-
不清楚如果有几个这样的项目部分并且“更新”超出了可见区域,它应该是什么样子,然后我们滚动到底部......?
-
滚动到底部,它将位于标签栏上方。在自动布局中,我相信会固定到具有高优先级的底部安全区域和固定在最后一个部分下方的优先级较低的区域
-
我开始认为这不能在 SwiftUI 中完成。也许我应该将其设置为粘性页脚,除非列表大于屏幕高度。听起来很乱
标签: swiftui swiftui-list