Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making the title bar of a window completely transparent

i'm working on an macos app in Swift 3, where I'd like to make the title bar transparent, and not show the title of my app, so basically, just the 3 buttons (close, minify, fullscreen) on my background.

What I tried is to put the following in the viewDidLoad method of the first view controller that is being used:

self.view.window?.styleMask.insert(NSWindowStyleMask.unifiedTitleAndToolbar)
self.view.window?.styleMask.insert(NSWindowStyleMask.fullSizeContentView)
self.view.window?.styleMask.insert(NSWindowStyleMask.titled)
self.view.window?.toolbar?.isVisible = false
self.view.window?.titleVisibility = .hidden
self.view.window?.titlebarAppearsTransparent = true

but what I end up with is this:

enter image description here

it seems like the title bar has got a lower opacity then normal, but I'd like it (and the app title) gone completely.

Am I missing something or is this impossible?

Thanks.

like image 710
Wesley Avatar asked Sep 06 '25 02:09

Wesley


1 Answers

The problem is that inside viewDidLoad method the window property is always nil. All the optional chaining in your code just fails silently. You just need to move your code to viewWillAppear method.

override func viewWillAppear() {
    super.viewWillAppear()

    // configure your window properties here
}
like image 79
Leo Dabus Avatar answered Sep 09 '25 07:09

Leo Dabus