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

TJ罗杰斯

这是我的代码:

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")
                }
            }
        }
    }
}

问题是我无法以相同的方式让section header的两行对齐或对齐。我希望它们都左对齐,但是我也希望它们都以屏幕为中心。实际上,对齐方式很奇怪,如下所示:

奇数文字对齐

任何建议将不胜感激。

达维杰夫

添加VStack对齐

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

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章