2015-01-20 9 views
2

Swift를 처음 사용하며 AppCode (Xcode 사용을 원하지 않음)를 사용하여 스토리 보드 또는를 사용하지 않고 OS X 응용 프로그램을 개발하고 싶습니다. xib 파일. 그래서 UI를 만들고 콘센트와 액션을 프로그래밍 방식으로 관리해야합니다. UI가 프로그래밍 방식으로 생성되는 "Hello World"또는 샘플 앱의 샘플 코드/자습서 비디오에 대한 링크를 찾고 있습니다. 도움을 감사하십시오. 감사합니다.Swift에서 OS X 용 프로그래밍 방식으로 UI 작성 (Interface Builder 또는 nib 파일 사용 안 함)

+1

당신의 근거는 무엇입니까? –

+0

@SergioTulentsev : 이유가 무엇인가요? AppCode를 사용하거나 UIStuff을 사용하지 않습니까? – YvesLeBorg

+0

스토리 보드 등을 사용하지 마십시오. 사과가 네가 그걸 어떻게하기를 바라는가? –

답변

-1
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 
    } 
} 
+2

안녕하세요! Xcode에서 스 니펫이 작동하지 않는 것 같습니다. 어떻게 사용할 수 있도록 구성해야합니까? 'MainMenu.xib'파일을 휴지통으로 이동하고 프로젝트 정보에서 참조를 제거하려고 이미 시도했습니다. 그 후 AppDelegate.swift 내에서 코드 조각을 시도했지만 Xcode에서 앱을 빌드하자마자 창이 나타나지 않고 대신 두 개의 오류가 발생합니다. _ (view 및 colorGridView) 콘센트에 연결하지 못했습니다 (NSApplication) ~ (NSColorPickerGridView) : 누락 된 setter 또는 인스턴스 변수 _ 앱을 실행하려면 무엇을해야합니까? 감사! =) – Leonard