4

I am creating a custom NSWindow with no title bar and am using NSBorderlessWindowMask to make it completely borderless. The problem I have with this however is that the window has sharp edges. As well as this there is no resize control.

How would I give a borderless window rounded corners?

This is not a duplicate of this question as that question was more about removing the title bar and it currently holds no answers.

Community
  • 1
  • 1
Joshua
  • 15,200
  • 21
  • 100
  • 172
  • You might be looking for something like [this](http://stackoverflow.com/questions/19940019/nswindow-with-round-corners-and-shadow/27613308#27613308). This is bordered style, but seems close to what you're looking for. – eonil Jan 02 '16 at 04:15

3 Answers3

8

You can make the window totally transparent and handle drawing everything yourself. The sample I have is for an OpenGL view, but it should work for a Quartz view or Cocoa view as well.

Add the following to the initializer of your NSWindow subclass where you create the new window using the NSBorderlessWindowMask constant.

[self setOpaque:NO];
[self setBackgroundColor:[NSColor clearColor]]; 

You will probably have to draw the resize control yourself. The sample I took this from is a full screen window so resizing isn't necessary.

Good Luck.

Mark
  • 6,108
  • 3
  • 34
  • 49
  • Where would I handle drawing everything? – Joshua Jan 04 '11 at 13:09
  • In your view class' -drawRect: override. You will need a drawing context to draw into so subclass either NSImage or NSOpenGLView. I misspoke, the code I gave you in my answer should be in your NSWindow subclass. You will also need a custom view subclass to do the drawing. – Mark Jan 04 '11 at 13:18
  • 1
    Going on what you gave me, I was able to find this tutorial on Cocoa With Love. Consider your answer accepted! http://cocoawithlove.com/2008/12/drawing-custom-window-on-mac-os-x.html – Joshua Jan 04 '11 at 13:31
  • Thanks for the link. I've been reading Cocoa With Love for years but didn't know about that tutorial. – Mark Jan 04 '11 at 14:29
0

The easiest way to get a window with rounded corners is to place a NSBox into the window as these boxes have customizable rounded corners and customizable borders. If you then set the window to non-opaque and the background color to transparent ("clear color"), you have a NSWindow with rounded corners that draws a normal window shadow (even on older systems where such a window would otherwise not have a shadow). Most of it can be done in Interface Builder. See here for details.

Mecki
  • 125,244
  • 33
  • 244
  • 253
0

Only titled windows get the rounded corners. So the only thing you have to do is this:

window.styleMask = [.titled]
window.titleVisibility = .hidden
window.titlebarAppearsTransparent = true

This should be the minimal configuration for a rounded window without a title bar.

  • But then you're stuck with a bottom border. That's what I've found. When I turn the bottom border off, I get an error compiling. "regular border style windows not using Autosize for the Top Content Border property (Other values are explictly unsupported at runtime and will lead to an exception" – Tap Forms Jul 09 '22 at 19:34