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
I guess the answer is a bit late :) but still might help somebody.
Here is a solution for SwiftUI application:
NSWindow you can check one of these answers:So in the end you will end up with something like this:
var window: NSWindow?
.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
Building upon @alexey-pichukov post, the SwiftUI version to toggle the tabGroup on
.onAppear {
DispatchQueue.main.async {
NSApp.windows.forEach { window in
if let tabGroup = window.tabGroup {
window.toggleTabBar(.none)
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With