How to show NavigationLink as a button in SwiftUI

后端 未结 8 2058
说谎
说谎 2021-01-31 14:39

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

8条回答
  •  生来不讨喜
    2021-01-31 15:20

    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.

提交回复
热议问题