I\'ve read a lot here about navigation in SwiftUI and tried a couple of things, but nothing is working as desired.
Basically, I have a view with a list of workouts and y
I don't know why all these answers are making this so complicated. In SwiftUI 2.0, you just add the button inside the navigation link!
NavigationLink(destination: TimerView()) {
Text("Starten")
}
You can apply SwiftUI styling to the Text
object just as you would style any other element.
I've been playing around with this for a few days myself. I think this is what you're looking for.
struct WorkoutDetail: View {
var workout: Workout
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: TimerView()) {
ButtonView()
}.navigationBarTitle(Text(workout.title))
}
}
}
And create a View you want to show in the NavigationLink
struct ButtonView: View {
var body: some View {
Text("Starten")
.frame(width: 200, height: 100, alignment: .center)
.background(Color.yellow)
.foregroundColor(Color.red)
}
Note: Anything above the NavigationView appears to show up on all pages in the Navigation, making the size of the NavigationView Smaller in the links.