I’ve been working on this for the past two days, but in a UIKit Mac Catalyst context. I managed to get it working, though I believe this might actually be a bug in Mac Catalyst. I was about to file a report when I came across your post. Did you already submit one?
The workaround I found is to assign an instance of NSToolbar to the windowScene's titlebar like this:
// Inside SceneDelegate.swift
#if targetEnvironment(macCatalyst)
let toolbar = NSToolbar()
toolbar.displayMode = .iconOnly // reduces toolbar height
self.window?.windowScene?.titlebar?.toolbar = toolbar
#endif
This setup gives you the unified sidebar and toolbar, but there’s still quite a bit of empty space at the top, even with displayMode set to .iconOnly. Since I didn’t actually need a toolbar in my case, I fixed it by applying a negative top safe area inset. That gave me the look I wanted:
let splitViewController = UISplitViewController(style: .doubleColumn)
let sidebarNavigationController = KNavigationController(rootViewController: SidebarViewController())
#if targetEnvironment(macCatalyst)
sidebarNavigationController.additionalSafeAreaInsets.top = -28 // roughly the titlebar height
splitViewController.additionalSafeAreaInsets.top = -28
#endif
splitViewController.setViewController(sidebarNavigationController, for: .primary)
Before
After
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: