How to hide the tab bar in SwiftUI's TabView for macOS?

In SwiftUI for macOS, how can I hide the tab bar when using TabView? I would like to provide my own tab bar implementation.

In AppKit's NSTabViewController, we can do the following:

let tabViewController = NSTabViewController()
tabViewController.tabStyle = .unspecified

I've come across various posts that suggest using the .toolbar modifier, but none appear to work on macOS (or at least I haven't found the right implementation).

struct ContentView: View { 
  var body: some View { 
    TabView { 
      // ... content
    } <- which view modifier hides the tab bar?
  }
}

Latest macOS, Latest Xcode

Hi @kennyc,

We suggest using native UI elements, but you could hide the Toolbar with .toolbar(.hidden).

Is that the behavior you're hoping for?

-J

We suggest using native UI elements

Are you suggesting that I forgo using SwiftUI's TabView and instead use NSTabView from AppKit? I'm currently using NSTabViewController but was hoping to reduce my dependencies on AppKit and adopt SwiftUI as much as possible.

We suggest using native UI elements, but you could hide the Toolbar with .toolbar(.hidden).

That seems to hide the window's toolbar. I'm trying to hide the tab bar as presented by TabView on macOS, which I presume is using NSTabView. As noted above, NSTabViewController allows you to hide the tab bar and NSTabView itself offers NSTabPosition.None.

However, I'm unable to configure those withTabView and thus, on macOS, I'm left with the default "Aqua-style" tab bar, which I don't want.

Hi @kennyc,

When using SwiftUI's TabView, what I was suggesting is using the native tab bar for navigation instead of a custom solution:

I would like to provide my own tab bar implementation.

Using TabView allows your content to adapt to different devices and screen sizes, among other advantages. (Some of which are laid out in this article) There are also tab view styles and behaviors that can be customized.

I suppose instead of using SwiftUI's Tabs you could make your own custom implementation altogether to switch between views, maybe even a custom ViewBuilder. But as far as I'm aware there's no way to use TabView and then hide the SwiftUI tab bar navigation.

-J

How to hide the tab bar in SwiftUI's TabView for macOS?
 
 
Q