I am simply trying to open up a new view when the user clicks a button. What is the most simple, and easiest way to do this using Swift API?
//Login Button
Button(
action:
{
// Open Signup Screen
Signup();
},
label:
{
// How the button looks li
Text("Create New Account")
.foregroundColor(.white)
.font(.title)
}
)
.frame(maxWidth: .infinity, alignment: .center)
.background(Color(red: 0.22, green: 0.655, blue: 0.02))
.cornerRadius(8)
.padding(.horizontal, metrics.size.width*0.10)
}
Thanks.
Isaiah Thompson
2
Answers
The best way would be to use a
NavigationLink
and wrapping the content inside aNavigationView
.The
NavigationView
is used to represent the view hierarchy.For instance:
You can find more info in the official docs:
Also [Hacking With Swift] (https://www.hackingwithswift.com/quick-start/swiftui/displaying-a-detail-screen-with-navigationlink) is a great resource for SwiftUI