Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent Toolbar in Mac Catalyst

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?

like image 307
Lupurus Avatar asked Nov 08 '19 23:11

Lupurus


People also ask

How do I get rid of Windows toolbar on Mac?

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 .

What is the title bar on Mac?

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.

How to show toolbar on MacBook Air?

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.

What does the title bar look like on a Mac?

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.

How do I remove an item from the toolbar on Mac?

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.)

Is it possible to run UIViewController on Mac catalyst?

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.


2 Answers

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
}
like image 89
Muhammet Balsoy Avatar answered Oct 15 '22 07:10

Muhammet Balsoy


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
    
    
}
like image 38
YESME Avatar answered Oct 15 '22 07:10

YESME