使用Dark Transparency使标题栏和视图控制器无缝连接

时间:2015-10-08 05:12:57

标签: macos swift titlebar nsvisualeffectview

嗨,所以我一直在互联网上查找,并找到了关于这个主题的各种有用的信息,但似乎都没有工作

如果想要得到这样的东西 enter image description here

标题栏和窗口的其余部分混合在一起。从互联网上到目前为止,代码iv已经在我的viewDidLoad()

    self.view.window?.appearance = NSAppearance(named: NSAppearanceNameVibrantDark)
    self.view.window?.styleMask = (self.view.window?.styleMask)! | NSFullSizeContentViewWindowMask
    self.view.window?.titlebarAppearsTransparent = true
    self.view.window?.movableByWindowBackground = true

但那不做任何事情。我是Mac开发的新手(通常是ios)所以非常感谢所有的帮助!

1 个答案:

答案 0 :(得分:4)

创建NSWindowController的子类并将您的代码放在windowDidLoad()中。

override func windowDidLoad() {
    super.windowDidLoad()

    // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
    self.window?.appearance = NSAppearance(named: NSAppearanceNameVibrantDark)
    self.window?.styleMask = (self.window?.styleMask)! | NSFullSizeContentViewWindowMask
    self.window?.titlebarAppearsTransparent = true
    self.window?.movableByWindowBackground = true
}