I have a simple SwiftUI screen and I’m trying to get the buttons in the bottom to be horizontally centered. When I was typing in the text in the top section, the title text above it centered automatically, which is good. Seems like there should be a simple way to center all of the items in the bottom section without having to use a long text string.
Here’s the code:
import SwiftUI
struct Testing : View
{
func abc(){}
func def(){}
func xyz(){}
var body: some View
{
Form
{
Section
{
VStack
{
Text("Title")
.font(.largeTitle)
Text("And more text here. And the more text I'm adding, I see the title above centering automatically. Ok. Good.")
}
}
Section
{
VStack
{
Text("TODO: Center!")
Button("Abc", action: abc).buttonStyle(.borderedProminent)
Button("Def", action: def).buttonStyle(.borderedProminent)
Button("Xyz", action: xyz).buttonStyle(.borderedProminent)
}
}
} // Form
}
}
#Preview {
Testing()
}

