Ultimate Catalyst Guide

How do I modify the window?

released Fri, 05 Jul 2019
Swift Version 5.1

Preparations

Note that in Beta 2 you need to manually import a special bridging header if you want to modify the title. Here's how to do it.

The way to modify window titlebars is to use the UIScene API introduced with iOS 13. The gist is that you use a SceneDelegate and in the scene:willConnectToSession:options method, you can modify a window scene's titlebar.

If your project doesn't have a SceneDelegate yet, here's a brief primer on how to set it up.. This delegate is - as far as I'm aware - required to support toolbars.

UIWindowScene objects have a titlebar property on macOS. These UITitleBar objects are currently not documented, but the headers expose several properties:

  func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

         guard let windowScene = (scene as? UIWindowScene) else { return }

         #if targetEnvironment(UIKitForMac)

		windowScene.titlebar.titleVisibility = .hidden

		#endif

}