How to hide TabBar/TabView with SwiftUI

iOS 16 solution: .toolbar(.hidden, for: .tabBar)
struct ProfileView: View {
  var body: some View {
    Text("ProfileView")
      .toolbar(.hidden, for: .tabBar) /// <-- Hiding the TabBar for a ProfileView.
  }
}
iOS 13 – iOS 15 Solution:
  1. To hide TabBar when we jumps towards next screen we just have to place NavigationView to the right place. Makesure Embed TabView inside NavigationView so creating unique Navigation view for both tabs.
  2. For setting up navigation title use @State var tabArray with dynamic values.

import SwiftUI

struct TabBarView: View {
    
    @State var tabSelection: Int = 0
    @State var tabArray = ["Profile", "Settings"]
    
    var body: some View {
        NavigationView {
            TabView(selection: $tabSelection){
                ForEach(0 ..< tabArray.count, id: \.self) { indexValue in
                    NavigationLink(destination: DetailView()){
                        VStack{
                            Text("\(tabArray[indexValue]) tab -- Click to jump next view")
                        }
                    }
                    .tabItem {
                        Image(systemName: "\(indexValue).circle.fill")
                        Text(tabArray[indexValue])
                    }
                    .tag(indexValue)
                    
                }
            }
            .navigationBarTitle(tabArray[tabSelection])
        }
    }
}
struct DetailView: View {
    var body: some View {
        Text("Detail View")
            .navigationBarTitle("NavigatedView")
            .navigationBarTitleDisplayMode(.inline)
            .navigationTitle("helllo")
    }
}

Thats it 🙂 Complete Source code is here

Leave a Comment

Your email address will not be published. Required fields are marked *