[英]How to remove bottom padding of List and ScrollView in SwiftUI
我想刪除底部填充,紅色空間之間的白色空間。 有什么辦法可以實現嗎?
測試代碼:
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
才能沒有間距。 默認情況下,它根據上下文采用默認空間
VStack(spacing: 0) {
// the same result with using List instead of ScrollView
ScrollView {
.........
}
只需使用 GeometryReader
@State var contentSize: CGSize = .zero
ScrollView {
YourContentView()
.overlay(
GeometryReader { geo in
Color.clear.onAppear {
contentSize = geo.size
}
}
)
}
.frame(maxWidth: .infinity, maxHeight: contentSize.height)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.