【发布时间】:2021-07-14 07:04:38
【问题描述】:
如何在 iOS 上使用 List 和 InsetGroupedListStyle 制作全角标题? 一种方法是使用负填充(作为我代码中的示例),但这似乎不是使用固定值的最佳解决方案,因为它可能会在未来发生变化。
有没有更好的办法?
示例代码:
import SwiftUI
struct ContentView: View {
var body: some View {
List {
Section (header:
VStack {
Text("Header")
.foregroundColor(.white)
}
.frame( // This doesn't remove list's paddings
minWidth: 0,
maxWidth: .infinity,
minHeight: 0,
maxHeight: .infinity,
alignment: .topLeading
)
.background(Color.red)
// .padding(.horizontal, -16) // This works, but fixed value is not the best solution.
.textCase(nil)
.font(.body)
) {
Text("Hello, world!")
.padding()
}
}
.listStyle(InsetGroupedListStyle())
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
【问题讨论】: