我是这种编程语言的新手,我想创建一个应用程序,当我点击按钮但是我不知道该怎么做时,会打开一个包含一些信息的窗口。
我没有使用故事板,因为我读到了专业编程这些不起作用。
我不想要iOS,我希望它适用于OS X.
关心所有人!
答案 0 :(得分:4)
这很简单。你可以这样做:
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
let myNewWindow = NSWindow(contentRect: NSMakeRect(0,0,640,480), styleMask: NSBorderlessWindowMask, backing: NSBackingStoreType.Buffered, defer: false)
// NSBorderlessWindowMask = 0,
// NSTitledWindowMask = 1 << 0,
// NSClosableWindowMask = 1 << 1,
// NSMiniaturizableWindowMask = 1 << 2,
// NSResizableWindowMask = 1 << 3,
// NSTexturedBackgroundWindowMask = 1 << 8
func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application
}
func applicationWillTerminate(aNotification: NSNotification) {
// Insert code here to tear down your application
}
@IBAction func btnNewWindow(sender: AnyObject) {
myNewWindow.opaque = false
myNewWindow.movableByWindowBackground = true
myNewWindow.backgroundColor = NSColor(hue: 0, saturation: 1, brightness: 0, alpha: 0.7)
myNewWindow.makeKeyAndOrderFront(nil)
}
}