没有XIB的Swift中的OS X应用程序

时间:2015-01-18 03:21:45

标签: ios macos cocoa swift nswindow

有没有人想办法在不使用XIB(或IB)的情况下引导基于NSWindow的应用程序?在iOS中,这非常简单;

func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
        window = UIWindow(frame: UIScreen.mainScreen().bounds)

        window!.rootViewController = ViewController(nibName: nil, bundle: nil)
        window!.makeKeyAndVisible()
        window!.backgroundColor = UIColor.whiteColor()
        return true
    }

但是我无法让它适用于桌面应用.. NSWindow没有makeKeyAndVisible()方法,NSApplicationDelegate似乎有十几个覆盖func application()..什么是神奇的咒语?

1 个答案:

答案 0 :(得分:-2)

import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
    @IBOutlet weak var window: NSWindow!
    let newWindow = NSWindow(contentRect: NSScreen.mainScreen()!.frame, styleMask: NSBorderlessWindowMask, backing: NSBackingStoreType.Buffered, defer: false)
    func applicationDidFinishLaunching(aNotification: NSNotification) {
        // Insert code here to initialize your application
        newWindow.opaque = false
        newWindow.movableByWindowBackground = true
        newWindow.backgroundColor = NSColor.whiteColor()
        newWindow.makeKeyAndOrderFront(nil)
    }
    func applicationWillTerminate(aNotification: NSNotification) {
        // Insert code here to tear down your application
    }

}