NSStackView
내 뷰를 차례로 배치하려면 어떻게해야합니까? 파란색 상자가 빨간색 상자 위에 그려져 있습니다.스위프트 NSStackView : 배우기. 내가 도대체 뭘 잘못하고있는 겁니까?
import Cocoa
class TestView : NSView{
override init() {
super.init(frame: NSRect(x: 0,y: 0,width: 100,height: 100))
}
required init(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func drawRect(dirtyRect: NSRect) {
super.drawRect(dirtyRect)
NSColor.redColor().setFill()
NSBezierPath.fillRect(self.bounds)
}
}
class TestView2 : NSView{
override init() {
super.init(frame: NSRect(x: 0,y: 0,width: 100,height: 100))
}
required init(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func drawRect(dirtyRect: NSRect) {
super.drawRect(dirtyRect)
NSColor.blueColor().setFill()
NSBezierPath.fillRect(self.bounds)
}
}
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
@IBOutlet weak var searchFacetItems: SearchFacetSelectorView!
@IBOutlet weak var searchFacetHeader: SearchFacetSelectorHeader!
var content : NSStackView!
let testView = TestView()
let testView2 = TestView2()
func applicationDidFinishLaunching(aNotification: NSNotification?) {
// Insert code here to initialize your application
content = NSStackView(frame: window.contentView.bounds)
content.orientation = NSUserInterfaceLayoutOrientation.Vertical
content.alignment = NSLayoutAttribute.CenterX
content.addView(testView, inGravity: NSStackViewGravity.Center)
content.addView(testView2, inGravity: NSStackViewGravity.Center)
window.contentView = content!
}
func applicationWillTerminate(aNotification: NSNotification?) {
// Insert code here to tear down your application
}
}
그것은 AppKit의 아니에요을 읽어 배우,하지만 어쩌면 내가 몇 가지 단서를 얻을 수 있습니다 : HOW TO USE UIVIEWS WITH AUTO LAYOUT PROGRAMMATICALLY
이전에 시도했지만 작동합니다. 그러나 나는 스택 뷰가 자신이 현명하게 관리하는 뷰를 레이아웃 할 것을 기대하고있다. –