I was able to create a unified toolbar in Mac Catalyst with this in the SceneDelegate.swift
:
// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView)
// hide the titlebar
windowScene.titlebar?.toolbar = NSToolbar()
windowScene.titlebar?.titleVisibility = .hidden
...
}
But I want to make the toolbar transparent like in this example: https://lukakerr.github.io/swift/nswindow-styles#11-transparent-toolbar-without-seperator
Is this even possible in Mac Catalyst?
If you choose to design your window without a title bar, you must remove it from the window. To remove the title bar, set the title bar's titleVisibility property to UITitlebarTitleVisibility. hidden and the toolbar property to nil .
A title bar is a small strip that extends across the top of a window. It displays the title of the window and typically includes the close, minimize, and maximize buttons. In macOS, these buttons are on the left side of the title bar, while in Windows, they are on the right.
On your Mac, click the Finder icon in the Dock to open a Finder window. Hide or show the toolbar: Choose View > Hide Toolbar, or View > Show Toolbar, in the menu bar. Hiding the toolbar also hides the sidebar, and moves the status bar from the bottom to the top of the window.
By default, Mac apps built with Mac Catalyst display a title bar across the top of their windows. A horizontal line separates the title bar from the content of the window. Some Mac apps such as Messages and Contacts have no title bar in their main window.
Remove an item: Press and hold the Command key, then drag the item out of the toolbar. On your Mac, click the Finder icon in the Dock to open a Finder window. Hide or show the sidebar: Choose View > Hide Sidebar, or View > Show Sidebar, in the menu bar. (If Show Sidebar is dimmed, choose View > Show Toolbar.)
To start with let's take a simple tab bar based app with a label in the UIViewController 's' telling us which view we are looking at. If we just take this app and compile and run it for mac Catalyst this is the result we get. This works... but feels a lot like running the app in the iOS simulator.
Yes, this is possible in Mac Catalyst. In your SceneDelegate.swift file, set both toolbar and title visibility to false
and .hidden
respectively.
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
#if targetEnvironment(macCatalyst)
windowScene.titlebar?.toolbar?.isVisible = false
windowScene.titlebar?.titleVisibility = .hidden
#endif
}
override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated)
#if targetEnvironment(macCatalyst)
if let titlebar = self.view.window?.windowScene?.titlebar {
titlebar.titleVisibility = .hidden
titlebar.toolbar = nil
}
#endif
}
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