How to make transparent or clear background title bar of UIWindowScene

MACCATALYST I am able to hide title bar title using below line.

windowScene.titlebar?.titleVisibility = .hidden

but,

windowScene.titlebar?.toolbarStyle = .unifiedCompact

windowScene.titlebar?.toolbar = nil

with above 2 lines, my title bar is still visible with system defined some background color.

I want to make it transparent(clear background color)

To make the title bar transparent in a UIWindowScene for Mac Catalyst, you can try the following approach. You'll need to access the NSWindow via the UIWindowScene and set its appearance properties directly, since Mac Catalyst allows you to interact with the AppKit layer.

Here’s how you can do it:

if let titlebar = windowScene.titlebar { titlebar.titleVisibility = .hidden titlebar.toolbar = nil

// Access the NSWindow
if let nsWindow = windowScene.value(forKey: "nsWindow") as? NSObject {
    nsWindow.setValue(true, forKey: "titlebarAppearsTransparent")
    nsWindow.setValue(false, forKey: "showsToolbarButton")
    nsWindow.setValue(0, forKey: "styleMask") // Removes any existing window decorations
}

}

This code snippet hides the toolbar and ensures the title bar is transparent by modifying the NSWindow properties. You need to ensure that you're interacting with the correct layer of the window system for this to work on Mac Catalyst.

How to make transparent or clear background title bar of UIWindowScene
 
 
Q