问题描述
使用 SwiftUI,我创建了一个 VStack,其中包含一些固定元素和一个列表元素.原因是,用户应该只滚动固定元素下的区域.现在我看到第二个固定元素和列表之间有一个空格.我不知道这个空间是从哪里来的,想摆脱它,但不知道如何.该区域以红色标记.
Using SwiftUI, I created a VStack, which contains some fixed elements and a list element. The reason is, that the user should only scroll the area under the fixed elements. Now I see a space between the second fixed element and the list. I don't know where this space is coming from and want to get rid of it, but have no idea, how. The area is marked in red.
struct DashboardView : View, CoreDataInjected {
var body: some View {
GeometryReader { geometry in
VStack {
ScopeSelectorView().frame(maxWidth: .infinity).background(ColorPalette.gray)
BalanceNumberView().frame(maxWidth: .infinity)
List {
DashboardNavigationView(
height: geometry.size.height - ScopeSelectorView.height - BalanceNumberView.height
).frame(maxWidth: .infinity).listRowInsets(.zero)
}
}
}.background(Color.red).edgesIgnoringSafeArea(.all)
}
}
推荐答案
由于您没有将 spacing
参数传递给 VStack
,它正在选择基于默认间距的上下文.如果不想要间距,请显式传递 0.
Since you didn't pass a spacing
argument to VStack
, it is picking a default spacing based on context. If you want no spacing, pass 0 explicitly.
VStack(spacing: 0) {
// content here
}
这篇关于SwiftUI:如何删除 VStack 中视图之间的边距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!