2

Can anybody tell me how I can get my NSWindow to show the TabBar (incl. the "+"-Button), even if I have only one tab?

I know there is a Menu Option called "Show Tab Bar" that will lead to the tab bar showing even if you have only one tab. How can I get this functionality programmatically?

See this example of a window showing the tab bar with only one tab open

Tterhuelle
  • 103
  • 9

1 Answers1

0

I guess the answer is a bit late :) but still might help somebody.

Here is a solution for SwiftUI application:

  1. To get the right instance of NSWindow you can check one of these answers:

So in the end you will end up with something like this:

var window: NSWindow?
  1. Add .onAppear modifier with the following code to your high level view in the app:
.onAppear {
    guard let window = window else { return }
    guard let tabGroup = window.tabGroup else { return }
    guard !tabGroup.isTabBarVisible else { return }
    window.toggleTabBar(.none)
}

It will trigger the same action as Show Tab Bar from Menu -> View

Alexey Pichukov
  • 3,377
  • 2
  • 19
  • 22