Created
April 24, 2021 04:42
-
-
Save rushairer/5d4d9013274883f209fb28a8cad49863 to your computer and use it in GitHub Desktop.
NavigationView with TabView Like the popular Chat apps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // ContentView.swift | |
| // Test | |
| // | |
| // Created by Abenx on 2021/4/24. | |
| // | |
| import SwiftUI | |
| import CoreData | |
| struct ContentView: View { | |
| @Environment(\.managedObjectContext) private var viewContext | |
| @State var tabTag = 1 | |
| var body: some View { | |
| NavigationView { | |
| TabView(selection: $tabTag) { | |
| List { | |
| NavigationLink( | |
| destination: Text("Tab Content 1"), | |
| label: { | |
| Text("Tab Content 1") | |
| }) | |
| } | |
| .navigationTitle("Tab1`") | |
| .tabItem { Text("Tab Label 1") }.tag(1) | |
| List { | |
| NavigationLink( | |
| destination: Text("Tab Content 2"), | |
| label: { | |
| Text("Tab Content 2") | |
| }) | |
| } | |
| .navigationTitle("Tab2") | |
| .tabItem { Text("Tab Label 2") }.tag(2) | |
| } | |
| .navigationTitle("Tab\(tabTag)") | |
| } | |
| } | |
| } | |
| 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