[英]SwiftUI Vertical List Section header padding in iOS 15
I have a List
with Sections
:我有一个包含
Sections
的List
:
List {
ForEach((1...3), id: \.self) { _ in
Section(
header: Text("My Section")
.font(.system(.title3))
.fontWeight(.bold)
.foregroundColor(.primary),
content: {
ForEach((1...5), id: \.self) { _ in
Text("My Row")
}
}
)
}
}
Here is the result on an iPhone 8 simulator with iOS 14.5:这是在 iOS 14.5 的 iPhone 8 模拟器上的结果:
And here the result on an iPhone 8 simulator with iOS 15:这是带有 iOS 15 的 iPhone 8 模拟器的结果:
I want iOS15 list to be equal to iOS14.5 one.我希望 iOS15 列表等于 iOS14.5 之一。 I can remove horizontal padding by adding
.listStyle(PlainListStyle())
to the List
but the header of the section still have different vertical padding.我可以通过将
.listStyle(PlainListStyle())
到List
来删除水平填充,但该部分的标题仍然具有不同的垂直填充。
Is there a way to have the same vertical header padding as iOS14.5 ?有没有办法拥有与 iOS14.5 相同的垂直标题填充?
Environment:环境:
Change list's style to GroupedListStyle
using the .listStyle()
modifier.使用
.listStyle()
修饰符将列表的样式更改为GroupedListStyle
。
.listStyle(GroupedListStyle())
Header without gray backgrounnd没有灰色背景的标题
.listStyle(PlainListStyle())
https://developer.apple.com/documentation/swiftui/liststyle https://developer.apple.com/documentation/swiftui/liststyle
You can try setting the defaultMinListHeaderHeight
in the environment:您可以尝试在环境中设置
defaultMinListHeaderHeight
:
List {
...
}
.environment(\.defaultMinListHeaderHeight, 16)
Finally, what suited me the most was to add最后,最适合我的是添加
if #available(iOS 15.0, *) {
UITableView.appearance().sectionHeaderTopPadding = 0
}
In AppDelegate didFinishLaunchingWithOptions
function在 AppDelegate
didFinishLaunchingWithOptions
函数中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.