I'd like to create a new window programmatically. I have the following code, and it builds, but my window doesn't show up. The only way I can make it visible is by adding it as a child window to the default 'window'. How can I make 'win' be an independent window?
@IBOutlet var window: NSWindow
func applicationDidFinishLaunching(aNotification: NSNotification?) {
var win = NSWindow(contentRect: NSMakeRect(100, 100, 600, 200),
styleMask: NSResizableWindowMask,
backing: NSBackingStoreType.Buffered, defer: true)
window.addChildWindow(win, ordered:NSWindowOrderingMode.Above)
}
What about adding:
win.makeKeyAndOrderFront(win)
For me on OSX (not iOS) using Swift and writing in vim
let win = NSWindow(contentRect: NSMakeRect(100, 100, 600, 200),
styleMask: NSResizableWindowMask,
backing: NSBackingStoreType.buffered, defer: true)
win.makeKeyAndOrderFront(win)
pops up a window
You also need a NSWindowController
to display the window:
let window = NSWindow(...)
let controller = NSWindowController(window: window)
controller.showWindow(self)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With