Create a new window with NSWindow

Create a new window with NSWindow

swift

 12,970

Solution 1

What about adding:

win.makeKeyAndOrderFront(win)
Copy

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)
Copy

pops up a window

Solution 2

You also need a NSWindowController to display the window:

let window = NSWindow(...)
let controller = NSWindowController(window: window)

controller.showWindow(self)

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)
}

 

 

Guess you like

Origin blog.csdn.net/weixin_42610770/article/details/132899006