Thanks to https://stackoverflow.com/questions/42762856/nswindow-with-round-corners-in-swift/42763305
I have come to something pretty close to what you want.
I created a project withn Storyboard.
The window I want rounded is the initial controller.
There are a few points to take care:
- even though it seems possible in IB to declare Appearance without titleBar, that creates side effect (like windowDidBecomeMain no more called). That may be the problem mentionned by janabana
- with the settings I propose, there is still a small line at the top, quasi invidible, but I could not get rid of it.
So, the solution:
In IB, set the windows as:
Title : whatever or empty
Hide title unchecked (will be done in code)
Appearance: TitleBar ON (see warning above)
Transparent Title Bar : OFF (will be done in code)
Full Size Content View: ON
Shadow: ON
Visible at Launch: ON
All other OFF except Restorable
Marke the WindowController as a subclass (see other thread https://forums.developer.apple.com/thread/125315)
class FirstWindowController: NSWindowController, NSWindowDelegate {
var firstAppearance = true
override func windowDidLoad() {
super.windowDidLoad()
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}
func windowDidBecomeMain(_ notification: Notification) {
if firstAppearance {
let newFrame = NSRect(x: 120, y: 100, width: 300, height: 200)
self.window?.setFrame(newFrame, display: true)
let effect = NSVisualEffectView(frame: newFrame) // NSRect(x: 0, y: 0, width: 0, height: 0))
effect.blendingMode = .behindWindow
effect.state = .active
if #available(OSX 10.14, *) {
effect.material = .contentBackground
} else {
// Fallback on earlier versions
effect.material = .dark
}
effect.wantsLayer = true
effect.layer?.cornerRadius = 30.0
effect.layer?.borderColor = .clear
self.window?.contentView = effect
self.window?.titlebarAppearsTransparent = true
self.window?.titleVisibility = .hidden
self.window?.isOpaque = false
self.window?.backgroundColor = .clear
}
firstAppearance = false
}
}