Skip to content

Instantly share code, notes, and snippets.

@mralexhay
Last active April 21, 2022 01:47
Show Gist options
  • Save mralexhay/ef6ed9554c622bb2a8c63a9363e198e8 to your computer and use it in GitHub Desktop.
Save mralexhay/ef6ed9554c622bb2a8c63a9363e198e8 to your computer and use it in GitHub Desktop.
SwiftUI NavViews in TabView
struct ContentView: View {
var body: some View {
TabView {
ForEach(0 ..< 13) { i in
ColorView(index: i)
}
}
.ignoresSafeArea(.all)
.navigationViewStyle(.stack)
.tabViewStyle(.page(indexDisplayMode: .never))
}
}
struct ColorView: View {
let colorArray: [Color] = [.blue, .green, .cyan, .orange, .purple, .indigo, .teal, .mint, .pink, .yellow, .red, .black, .secondary]
var index: Int
var body: some View {
NavigationView {
colorArray[index]
.ignoresSafeArea(.all)
}
.overlay {
Text("Page \(index + 1)")
.foregroundColor(.white)
.font(.title.bold())
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment