SwiftUI 中列表的左对齐或居中对齐多行部分标题

问题描述

这是我的代码

struct ContentView: View {

    var body: some View {
        Form {
            Section(header:
                vstack {
                    Text("Header line 1")
                    Text("This is header line 2")
            }) {
                List {
                    Text("Item 1")
                    Text("Item 2")
                    Text("Item 3")
                    Text("Item 4")
                }
            }
        }
    }
}

问题是我无法让节标题的两行以相同的方式对齐或对齐。我更喜欢它们都是左对齐的,但我也会让它们都居中在屏幕上。原来,对齐方式很奇怪,如下图:

Odd Text Alignment

任何建议将不胜感激。

解决方法

添加 VStack 对齐

Section(header:
    VStack(alignment: .leading) { //<< here alignment
        Text("Header line 1")
        Text("This is header line 2")
}) 

enter image description here