我有一个简单的观点:
var body: some View {
NavigationView {
List(months) { month in
NavigationLink {
MonthView(month: month)
} label: {
VStack(alignment: .center, spacing: 8, content: {
Text("abc")
Text("abcdef")
Text("a")
})
}
.listRowBackground(
Color(uiColor: mode.darkUnderlayBackgroundColor)
.clipped()
.cornerRadius(10)
)
}
.navigationTitle(months.first?.descriptiveYear ?? "")
}
}
结果是:
如何将其置于整个 View 的中心?
最佳答案
您只需使用.frame
修饰符将maxWidth
设置为无穷大
。这将允许它水平扩展以占据所需的空间
VStack(alignment: .center, spacing: 8) {
Text("abc")
Text("abcdef")
Text("a")
}
.frame(maxWidth: .infinity)
关于swift - 如何使用 SwiftUI 将 VStack 在 List 内水平居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75215109/