Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Window title bar appears transparent issue (Not really transparent)

I am trying to make my app have more 'flat' feel so I think it is a good idea to hide the title bar.

However, in reality titlebarAppearsTransparent seems only remove the title bar shadow but not make the title bar truly transparent.

Before using any code to modify the title bar,

enter image description here

After adding the following code (starting have a better feel),

self.window?.titlebarAppearsTransparent = true

enter image description here

Setting the background color to white,

    self.window?.backgroundColor = NSColor.whiteColor()
    self.window?.titlebarAppearsTransparent = true

enter image description here

This is certainly not what I want. I thought I just turned the title bar transparent to true. What is going on here?

Any hint or comment is appreciated and thanks for your time viewing this question.

like image 450
X.Creates Avatar asked Dec 19 '22 18:12

X.Creates


1 Answers

Try add:

self.window?.styleMask |= NSFullSizeContentViewWindowMask

When set, the content view consumes the full size of the window; it can be combined with other window style masks, but is only respected for windows with a title bar. Using this mask opts in to layer backing. Use the contentLayoutRect or contentLayoutGuide to lay out views underneath the title bar-toolbar area

If you don't want to keep the title bar at all, you can also added:

self.window?.titleVisibility = NSWindowTitleVisibility.Hidden;

The window hides the title and moves the toolbar up into the area previously occupied by the title.

You might also wanted to add this in order to move the window by dragging its content view:

self.window?.movableByWindowBackground = YES

A Boolean value that indicates whether the window is movable by clicking and dragging anywhere in its background. The value of this property is YES when the window is movable by clicking and dragging anywhere in its background; otherwise, NO.

like image 159
Cai Avatar answered Apr 12 '23 23:04

Cai