Apologies if this has been asked/answered; I am trying to present a NavigationLink inside of a form, but would like it to be centered. I can do this with a Button using HStack and Spacers; the NavigationLink is a tat more stubborn:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
Form {
HStack {
//BUTTON CENTERS WITH SPACERS
Spacer()
Button(action: {}, label: {
Text("Button")
})
Spacer()
}
HStack {
//NAVIGATIONLINK IGNORES SPACERS
Spacer()
NavigationLink(
destination: Text("Destination"),
label: {
Text("Navigate")
})
Spacer()
}
}
}
}
}
One way that I like to do this is by creating an empty navigation link.
Then create a custom button with a toggle.
You can use any button, even custom ones, or even an onTapGesture, just by changing that boolean value. From there it's as simple as centering as you would any other element and you don't have to rely on the "Navigation Link" style that you're being presented with. Alternatively you can do something like this.