CodeX
Published in

CodeX

How to Navigate Between Views in Swift UI.

Photo by Jamie Street on Unsplash
struct SomeView: View {
var body: some View {
NavigationView {
Text("Hello.")
}
}
}
struct SomeView: View {
var body: some View {
NavigationView {
VStack {
Text("Navigation Link below:")
NavigationLink(destination: SecondView()) {
Text("Navigate here.")
}
}
}
}
}
struct SecondView: View {
var body: some View {
Text("Now on the second view.")
}
}
Example of Navigation Link
struct SomeView: View {
var body: some View {
NavigationView {
VStack {
Text("Navigation Link Below:")
NavigationLink(destination: SecondView()) {
Text("Navigate Here")
.foregroundColor(.black)
.font(.system(size:30))
.fontWeight(.bold)
}
}
}
}
}
Stylized Navigation Link
struct SomeView: View {
var body: some View {
NavigationView {
VStack {
Text("Navigation Link Below:")
NavigationLink(destination: SecondView()) {
Text("Navigate Here")
.foregroundColor(.black)
.font(.system(size:30))
.fontWeight(.bold)
}
}.navigationBarTitle("Page One")
}
}
}
Navigation Bar Title
struct SomeView: View {
var body: some View {
NavigationView {
VStack {
Text("Navigation Link Below:")
NavigationLink(destination: SecondView()) {
Text("Navigate Here")
.foregroundColor(.black)
.font(.system(size:30))
.fontWeight(.bold)
}
}.navigationBarTitle("Page One", displayMode: .inline)
}
}
}
Inline Navigation Bar Title

--

--

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store