【发布时间】:2021-10-05 12:32:37
【问题描述】:
在 iOS 15 上使用以下代码,标题文本与 List 中的文本对齐:
List {
Section {
Text("Hello, world!")
} header: {
Text("Section Header").sectionHeaderStyle()
}
}
.listStyle(InsetGroupedListStyle())
//...
public extension Text {
func sectionHeaderStyle() -> some View {
self
.font(.system(.title3))
.fontWeight(.bold)
.foregroundColor(.primary)
.textCase(nil)
}
}
然而,在 iOS 14 上,类似的代码将标题与列表部分本身对齐:
List {
Section(header: Text("Section Header").sectionHeaderStyle()) {
Text("Hello, world!")
}
}
.listStyle(InsetGroupedListStyle())
有谁知道如何获得 iOS 14 的行为,即部分标题与列表部分本身对齐,而不是与部分中的文本对齐?
【问题讨论】:
-
也许可以尝试硬编码的
offSet... 或者直接使用它。与 SwiftUI 设计变更作斗争非常乏味。 -
毫无疑问 - 我希望有一个我不知道的明显的新修饰符。特别奇怪的是,今年在 UIKit 端引入了显着的InsetGroupedHeader,使得在 UIKit 中更容易获得这种外观,但在 SwiftUI 中更难获得这种外观:developer.apple.com/documentation/uikit/…