iosmac-catalystuiwindowscene

How to change the window title in a Mac Catalyst window scene?


I'm opening multiple scenes in the Mac Catalyst version of my iPad app. The problem is that all of the windows simply show my app name in each window title. This makes it confusing looking at the list of windows in the Window menu. Plus I want to specific information to appear in the window title beside the app name.

UIWindowScene has a promising Mac Catalyst-only property named titleBar of type UITitleBar. Sounds promising but it has nothing related to setting any kind of title. Strange.

There's nothing I can find in the UIWindowScene or UIWindow classes or anything related to scenes.

I have also tried setting the title of the window's rootViewController. That had no effect. I also tried various values for the representedURL property of UITitlebar but that is used for things other than changing the title.

Is there any way to set a window's title in a Mac Catalyst app?


Solution

  • I don't know how I missed it but it turns out this is trivial.

    The UIScene class has a title property which is exactly what is needed. The value of this property is what is shown in the iPad app switcher as well as in the title bar of the iPad app running on a Mac.

    Setting it to nil defaults to the app name. Setting it to the empty string shows no title. And of course setting it to any other value shows that title.