3

我是 Swift 新手,我想使用 AppCode(我不想使用 XCode)开发一个 OS X 应用程序,并且没有故事板。所以我需要构建 UI 并以编程方式管理插座和操作。我正在寻找“Hello World”的示例代码/教程视频的链接或以编程方式创建 UI 的示例应用程序。感谢帮助。谢谢

4

1 回答 1

0
import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
    let newWindow = NSWindow(contentRect: NSMakeRect(0, 0, NSScreen.mainScreen()!.frame.width/2, NSScreen.mainScreen()!.frame.height/2), styleMask: NSTitledWindowMask|NSResizableWindowMask|NSMiniaturizableWindowMask|NSClosableWindowMask, backing: NSBackingStoreType.Buffered, defer: false)
    let newText = NSTextField(frame: NSMakeRect(0, NSScreen.mainScreen()!.frame.height/4, NSScreen.mainScreen()!.frame.width/2, 40))
    let myView = NSView(frame: NSMakeRect(0, 0, NSScreen.mainScreen()!.frame.width/2, NSScreen.mainScreen()!.frame.height/2))

    func applicationDidFinishLaunching(aNotification: NSNotification) {
        // Insert code here to initialize your application
        newText.font = NSFont(name: "Arial Black", size: 24)
        newText.backgroundColor = NSColor.clearColor()
        newText.bordered = false
        newText.textColor = NSColor.whiteColor()
        newText.alignment = .CenterTextAlignment
        newText.stringValue = "Hello World"
        newText.selectable = false
        newWindow.opaque = false
        newWindow.movableByWindowBackground = true
        newWindow.backgroundColor = NSColor(calibratedHue: 0, saturation: 1.0, brightness: 0, alpha: 0.7)
        newWindow.title = "Hello World"
        newWindow.center()
        newWindow.contentView.addSubview(myView)
        myView.addSubview(newText)
        newWindow.makeKeyAndOrderFront(nil)
    }

    func applicationWillTerminate(aNotification: NSNotification) {
        // Insert code here to tear down your application
    }
}
于 2015-01-20T07:35:49.350 回答