Window title bar appears transparent issue (Not really transparent)

依然范特西╮ 提交于 2020-01-04 04:00:31

问题


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,

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

self.window?.titlebarAppearsTransparent = true

Setting the background color to white,

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

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.


回答1:


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.



来源:https://stackoverflow.com/questions/35944792/window-title-bar-appears-transparent-issue-not-really-transparent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!