41

I am currently using Swift in Xcode 6, Beta 5. I am trying to remove the title bar, or any visible difference between the title bar and the actual content. If I enable "Unified title and toolbar" in the Attributes Inspector on a Window, nothing visibly happens. I have already left the title out.
When no title is entered, the title bar will still be distinguishable because of the border line and background difference with the rest of the window, separating it from the actual content.


An excellent example would be the current Yosemite, OS X 10.10, Notes app. No title bar is visible or distinguishable, just the Close, Minimise and Resize buttons as seen here. Screenshot of Notes window

I have searched and visited other posts, but to no to little avail.
Those mentioned hiding the title bar altogether, but I wouldn't know how to manually re-add the Close, Minimise and Resize buttons properly, meaning they would look correct, no actual, sneaky image replacements and connections with the menu bar Close, Minimise and Resize functions.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Isaiah
  • 1,852
  • 4
  • 23
  • 48

7 Answers7

44

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

Chad Cache
  • 9,668
  • 3
  • 56
  • 48
Renfei Song
  • 2,941
  • 2
  • 25
  • 30
  • Current version of Xcode does not compile operator of type `|=` – ixany Oct 25 '16 at 08:48
  • 3
    @ixany that is because Swift once again changed the language in a backwards incompatible way :| NSWindoStyleMask is an OptionSet; the current OptionSet documentation is [here](https://developer.apple.com/reference/swift/optionset) and the current approach seems to be the `insert()` method. – andlabs Oct 25 '16 at 14:01
21

Since MacOS X 10.10, you can use these:

if #available(macOS 10.10, *) {
    window.titlebarAppearsTransparent = true
}

if #available(macOS 10.2, *) {
    window.movableByWindowBackground  = true
}

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

Mikael
  • 2,355
  • 1
  • 21
  • 45
Cai
  • 3,609
  • 2
  • 19
  • 39
  • Could you link me to the sample project? I cannot find it. – Maximilian Litteral Mar 31 '16 at 02:15
  • @Maximilian sorry it was 2 years ago, I no longer have the link. But the answers here pretty much covered them, even with Swift version. – Cai Mar 31 '16 at 02:19
  • Ya, I'm trying to figure out how to make a mac app coming from iOS. Can't find much sample code, and none with a storyboard. I can't get a reference to the window. Tried a few different ways, always nil? Edit: Finally got it. Made a window controller and put it in windowDidLoad – Maximilian Litteral Mar 31 '16 at 02:52
  • If I implement `titlebarAppearsTransparent` it also hides the close and minimize buttons – ixany Oct 25 '16 at 08:50
16

For Swift 3 :-

self.window.titleVisibility = .hidden
self.window.titlebarAppearsTransparent = true
self.window.styleMask.insert(.fullSizeContentView)
Jay Mehta
  • 1,511
  • 15
  • 20
13

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

  1. Select the window from Story Board enter image description here

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

enter image description here

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

enter image description here

Fangming
  • 24,551
  • 6
  • 100
  • 90
11

You can use these:

override func viewDidAppear() {
    super.viewDidAppear()

    self.view.window?.titlebarAppearsTransparent = true
    self.view.window?.movableByWindowBackground = true
}
Hossein
  • 3,755
  • 2
  • 29
  • 39
5

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)
}
Andrej Jurkin
  • 2,216
  • 10
  • 19
1

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;
Jeff U.
  • 616
  • 1
  • 6
  • 12