Xcode & Swift - Window without title bar but with close, minimize and resize buttons

﹥>﹥吖頭↗ 提交于 2019-11-29 18:49:37

If you are using storyboard, it's just a simple check box in the Inspector bar.

  1. Select the window from Story Board

  2. Check the Transparent Title Bar checkbox in the inspector window.

Here's how it looks like in the Story board. It looks the same when you build and run the application.

Renfei Song

The new window style mask NSFullSizeContentViewWindowMask added in OS X 10.10 will do the trick.

self.window.titleVisibility = NSWindowTitleVisibility.Hidden;
self.window.titlebarAppearsTransparent = YES;
self.window.styleMask |= NSFullSizeContentViewWindowMask;

Release Notes

For 10.10+, you can use these:

window.titlebarAppearsTransparent = true
window.movableByWindowBackground  = true

There was an official sample project for window appearance in Yosemite. You might wanna check it out.

For Swift 3 :-

self.window.titleVisibility = .hidden
self.window.titlebarAppearsTransparent = true
self.window.styleMask.insert(.fullSizeContentView)

You can use these:

override func viewDidAppear() {
    super.viewDidAppear()

    self.view.window?.titlebarAppearsTransparent = true
    self.view.window?.movableByWindowBackground = true
}

Update Sept. 2017, taget 10.11:

override func viewDidAppear() {
    super.viewDidAppear()

    self.view.window?.titleVisibility = .hidden
    self.view.window?.titlebarAppearsTransparent = true
    self.view.window?.styleMask.insert(.fullSizeContentView)
}

I don't have enough reputation to comment on Ranfei Songs answer, but running on OSX 10.12 the syntax for the titleVisibility is slightly different, instead of this:

self.window.titleVisibility = NSWindowTitleVisibility.Hidden;

you'll need to use NSWindowTitleHidden instead, so updating Ranfei's code would result in you need to specify this like this:

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