我有一個List固定高度。我使用洗掉了所有插圖listRowInsets。
但是,22 點的填充仍然保留在節標題上方(隨著滾動開始縮小到零)。有沒有辦法洗掉節標題上方的額外填充?
更新:額外的填充僅出現在 iOS 15 運行時中。


如果我洗掉節標題(僅保留行ForEach),間距就會消失。

import SwiftUI
import Introspect
struct ContentView: View {
var body: some View {
ZStack {
Grid().opacity(0.1)
VStack {
Spacer(minLength: 60)
List {
Section(
header: HStack {
Text("Section Heaeder").font(.system(size: 40))
Spacer()
}
.frame(height: 60)
.background(Grid().opacity(0.4))
.listRowInsets(.zero),
content: {
ForEach(1...20, id: \.self) { eachRowIndex in
Text("Row \(eachRowIndex)")
.frame(height: 40)
.listRowInsets(.zero)
.listRowBackground(
Rectangle()
.strokeBorder(Color.white.opacity(0.2), lineWidth: 1)
)
}
}
)
}
.listStyle(.plain)
.introspectTableView {
$0.separatorStyle = .none
}
.background(Grid().opacity(0.1))
.padding(.leading, 20)
.padding(.trailing, 25)
.environment(\.defaultMinListRowHeight, 40)
}
}
.edgesIgnoringSafeArea(.all)
}
}
extension EdgeInsets {
static var zero = EdgeInsets()
}
struct Grid: View {
var body: some View {
Rectangle()
.fill(
ImagePaint(image: Image("Square"))
)
}
}
uj5u.com熱心網友回復:
適用于 iOS 15 及舊版本
if #available(iOS 15.0, *) {
yourTableView.sectionHeaderTopPadding = 0
} else {
UITableView.appearance().sectionHeaderTopPadding = CGFloat(0)
}
uj5u.com熱心網友回復:
使用
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/447185.html
上一篇:css中less是什么?
下一篇:透明部分標題?
