Hello, I'm trying to create game in macos with transperent titlebar. The title bar t stay transperent when I click inside, but changed to gray when the window resize or get out of focus. How can I make it stay transperent all the time?
I did all of this: window.styleMask.insert(.fullSizeContentView) window.titlebarAppearsTransparent = true window.titlebarSeparatorStyle = .none window.titleVisibility = .hidden window.isMovableByWindowBackground = true window.isOpaque = false window.backgroundColor = .black
in the swiftUI view created zstack that start with: var body: some View { ZStack { Color.black.ignoresSafeArea()
help please :) Thanks.
When I tried to create the bug in new project, I found the solution..
First, I added ".windowStyle(.hiddenTitleBar)" to the WindowGroup in my main app file. It prepares the window to be "borderless" before the system even draws it.
Standard applicationDidFinishLaunching logic was running too early for me. The OS was still setting up its default gray style and overwriting my code. I used a tiny timer to "force" my settings once the window is actually alive.
func applicationDidFinishLaunching(_ notification: Notification) {
// I used a 0.1s timer to catch the window AFTER the OS finishes its default setup
Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { timer in
if let window = NSApplication.shared.windows.first {
self.setupWindow(window)
timer.invalidate()
}
}
}
Then re-apply the transparency and separator settings in the windowDidBecomeKey delegate method to stop the "focus pop."
func windowDidBecomeKey(_ notification: Notification) {
guard let window = notification.object as? NSWindow else { return }
window.titlebarAppearsTransparent = true
window.titlebarSeparatorStyle = .none
window.backgroundColor = .black
}