swift - 窗口标题栏出现透明问题(不是真正透明)

标签 swift macos cocoa swift2

我试图让我的应用程序有更多的“扁平化”感觉,所以我认为隐藏标题栏是个好主意。

然而,实际上 titlebarAppearsTransparent 似乎只是去除了标题栏阴影,并没有使标题栏真正透明。

在使用任何代码修改标题栏之前,

enter image description here

添加如下代码后(开始有更好的感觉),

self.window?.titlebarAppearsTransparent = true

enter image description here

设置背景颜色为白色,

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

enter image description here

这当然不是我想要的。我以为我只是将标题栏透明化为 true。这是怎么回事?

感谢任何提示或评论,感谢您花时间查看此问题。

最佳答案

尝试添加:

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

如果你根本不想保留标题栏,你也可以添加:

self.window?.titleVisibility = NSWindowTitleVisibility.Hidden;

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

您可能还想添加此内容以便通过拖动其内容 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.

关于swift - 窗口标题栏出现透明问题(不是真正透明),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35944792/

相关文章:

ios - 如何将 NSArray 转换为特定的字符串?

objective-c - 编译器错误 : "initializer element is not a compile-time constant"

ios - 如何计算两个 UIColor 实例之间的颜色对比度

ruby-on-rails - class.save 错误 ruby​​ on rails

macos - 如何在 Mac 系统日志中找到蓝牙连接

macos - 使用高 CPU 时通知。通过 AppleScript 还是 Automator?

swift - 如何知道我的非 ViewController 类是否已加载(如 viewDidLoad)

cocoa OpenGL : draw texture and round corners

ios - 在 WatchKit 中使用 slider

ios - 如何在swift项目中使用ECSlidingViewController