user142019
user142019

Reputation:

Round corners on a borderless NSWindow

I'm creating an application and I don't want a title bar:

If the title remains the same all the time, does it make sense to show it? For example, if an app doesn’t show the names of documents, or any other assets that it opens, and there is plenty of space at the top around other controls to grab onto if you want to move the window around, does the title serve much purpose? https://i.sstatic.net/C9mTo.png

The problem is: how do I do this? I tried using [mainWindow setStyleMask:NSBorderlessWindowMask]; but I can't make it have round corners. I really don't know how to make round corners. Next to that, I can't make it have a resize control. If I use [mainWindow setStyleMask:NSBorderlessWindowMask | NSResizableWindowMask]; it's not borderless anymore. Can anyone help me? Thanks.

Upvotes: 5

Views: 5361

Answers (4)

Mecki
Mecki

Reputation: 132919

Creating a window with round corners can be easily done using a simple trick: Create a window with transparent background, place a NSBox into that window and us it as your content view. A NSBox already has round corners, customizable background color and customizable borders (style, color, and corner radius are customizable). Most of this can even be done in Interface Builder, actually only two lines of code are required in the end. For a full detailed example, see here.

Upvotes: 1

eonil
eonil

Reputation: 85975

Though this is a very old question...

Now it's easier on OS X 10.11.

        window1.backgroundColor             =   NSColor.whiteColor()
        window1.opaque                      =   false
        window1.styleMask                   =   NSResizableWindowMask
                                            |   NSTitledWindowMask
                                            |   NSFullSizeContentViewWindowMask
        window1.movableByWindowBackground   =   true
        window1.titlebarAppearsTransparent  =   true
        window1.titleVisibility             =   .Hidden
        window1.showsToolbarButton          =   false
        window1.standardWindowButton(NSWindowButton.FullScreenButton)?.hidden   =   true
        window1.standardWindowButton(NSWindowButton.MiniaturizeButton)?.hidden  =   true
        window1.standardWindowButton(NSWindowButton.CloseButton)?.hidden        =   true
        window1.standardWindowButton(NSWindowButton.ZoomButton)?.hidden         =   true

        window1.setFrame(CGRect(x: 400, y: 0, width: 400, height: 500), display: true)
        window1.makeKeyAndOrderFront(self)

Here's full working example.

This is a copied answer from another question. Seems a bit different, but can be answered equally.

Upvotes: 4

Stephen Furlani
Stephen Furlani

Reputation: 6856

If you want to do something completely different (like drawing your own window) check out Matt Gemmell's code. Look at MAAttachedWindow code for ways of removing the title bar, drawing bezier corners, and making it look superb.

Upvotes: 1

Nathan Kinsinger
Nathan Kinsinger

Reputation: 25021

There is a similar SO question here: Hide NSWindow title bar.

Basically if you use NSBorderlessWindowMask you can't use any other style mask so you will have to implement your own window controls and round the corners yourself.

Or you could use a regular NSWindow and just not set a title. See Tweetie.app for an example.

Hopefully Apple will provide new window styles with 10.7.

Upvotes: 1

Related Questions