0

在 iOS 15 上使用以下代码,标题文本与列表中的文本对齐:

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 15 上的列表标题对齐

然而,在 iOS 14 上,类似的代码将标题与列表部分本身对齐:

List {
    Section(header: Text("Section Header").sectionHeaderStyle()) {
        Text("Hello, world!")
    }
}
.listStyle(InsetGroupedListStyle())

iOS 14 上的列表标题对齐

有谁知道如何获得将节标题与列表节本身对齐而不与节内的文本对齐的 iOS 14 行为?

4

1 回答 1

2

在回答我自己的问题时,有人亲切地向我指出了headerProminence(.increased)修饰符,它可以在这里做我想要的。

于 2021-08-01T00:24:12.903 回答