Contents

UITitlebar

An object that you use to configure the title bar of a window in a Mac app built with Mac Catalyst.

Declaration

@MainActor class UITitlebar

Overview

Each UIWindowScene has a UITitlebar object available in Mac apps built with Mac Catalyst. You use this object to configure the title bar and its toolbar.

To show or hide a title in the title bar, set the titleVisibility property to UITitlebarTitleVisibility.visible or UITitlebarTitleVisibility.hidden. If you set the visibility to hidden and the title bar’s toolbar property is nil, the window displays only the window control buttons (Close, Minimize, and Zoom).

To add a toolbar to a window, create an NSToolbar object and assign it to the title bar’s toolbar property. To automatically hide the toolbar when the window enters full-screen mode, set the autoHidesToolbarInFullScreen property to true.

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    
    guard let windowScene = (scene as? UIWindowScene) else { return }
    
    #if targetEnvironment(macCatalyst)
    if  let titlebar = windowScene.titlebar {
        let identifier = NSToolbar.Identifier("com.example.apple-samplecode.toolbar")
        titlebar.toolbar = NSToolbar(identifier: identifier)
        titlebar.toolbar?.delegate = self
        titlebar.autoHidesToolbarInFullScreen = true
    }
    #endif
}

Topics

Configuring the title bar

Configuring the toolbar

See Also

Configuring a window’s title bar