Search code examples
swiftswiftuitabviewswift5ios-navigationview

How do I use a TabView with a NavigationView in SwiftUI?


I'm having the exact same issue like the person who posted this question:

NavigationView doesn't display correctly when using TabView in SwiftUI

Am I doing anything wrong or is it just a SwiftUI bug that'll be fixed?


Solution

  • Try adding .edgesIgnoringSafeArea(.top) to your TabView/ Top view

    struct ContentView: View {
        @State private var selection = 0
    
        var body: some View {
            TabView(selection: $selection){
                HomePageView()
                    .tabItem {
                        VStack {
                            Image(systemName: "house.fill")
                                .font(.title)
                        }
                    }
                    .tag(0)
                Text("Second View")
                    .font(.title)
                    .tabItem {
                        VStack {
                            Image(systemName: "bell.fill")
                                .font(.title)
                        }
                    }
                    .tag(1)
            }.edgesIgnoringSafeArea(.top)
        }
    }