0

I am working on a Mac app. I was wandering if it is possible to change the title bar colour in a NSWindow? I know how to remove it, but the problem with that is that it removes the three buttons as well (close, minimise, resize). I want to keep the three buttons but get rid of the bar.

Is there anyway to do this?

enter image description here

Supertecnoboff
  • 6,406
  • 11
  • 57
  • 98

2 Answers2

4

Swift Way

I was going a bit crazy trying to find this, couldn't believe when i worked it out that it was only two lines when all these answers that I was reading were so long!

Im my class ViewController I went to the viewDidAppear and added this to it.

override func viewDidAppear() {
        view.window?.titlebarAppearsTransparent = true
        view.window?.backgroundColor = NSColor.clearColor()
    }

So incredibly simple.

Steve
  • 4,372
  • 26
  • 37
3

Yes, it's been done here on SO:

How to Change Color of NSWindow Title Bar in OSX

They say that one-link answers are bad form here, but heck-- it does mostly what you're asking. And it works-- I've tried it myself.

The couple things to notice: his code there just works on the default window of NSApp... so you will need to do a bit of work to generalize it to the case of your / "any" NSWindow. ( Take that code that he puts in the AppDelegate and move it to your own subclass of NSWindow or your NSWindowController. Probably the controller. )

Also, he says to subclass NSView with "MyTitleView", but in the code, it's actually called "BlackTitlebarView"... Just pick one name, be consistent, and it's fine. Also, the color of the title text is in the drawString: method, where he has [NSColor whiteColor]. Also, he gets fancy with gradients, which you'll see when you run the code... If you don't need or want that, you can replace chunks of his code with simpler stuff to just draw a single color... but you might think about using the fancy stuff anyhow since you're getting it for free.

Community
  • 1
  • 1
zeppenwolf
  • 335
  • 1
  • 9
  • One-link answers are discouraged because you're answering for posterity, not just for the original asker. There's no guarantee that a particular link will still be alive a year from now. I have no idea whether that applies equally when linking to StackOverflow. :-) – Miles Erickson Sep 22 '15 at 15:08
  • You said "I have no idea whether that applies equally when linking to StackOverflow", and it seems extremely reasonable to suppose that it does NOT apply to an internal SO link. If SO dies, then the problem of dead links solves itself, n'est-ce pas? So I don't wanna be rude but I don't see the value of your comment. – zeppenwolf Sep 24 '15 at 03:11