2012-11-20 60 views

回答

6

這是不可能的界面生成器做的,但是你可以把它與編碼的點點做:

NSButton *closeButton = [window standardWindowButton:NSWindowCloseButton]; // Get the existing close button of the window. Check documentation for the other window buttons. 
NSView *titleBarView = closeButton.superview; // Get the view that encloses that standard window buttons. 
NSButton *myButton = …; // Create custom button to be added to the title bar. 
myButton.frame = …; // Set the appropriate frame for your button. Use titleBarView.bounds to determine the bounding rect of the view that encloses the standard window buttons. 
[titleBarView addSubview:myButton]; // Add the custom button to the title bar. 
0

雨燕2.2和自動佈局,創建一個「OK」按鈕向右標題欄:

let myButton = NSButton() 
myButton.title = "OK" 
myButton.bezelStyle = .RoundedBezelStyle 

let titleBarView = window!.standardWindowButton(.CloseButton)!.superview! 
titleBarView.addSubview(myButton) 
myButton.translatesAutoresizingMaskIntoConstraints = false 
titleBarView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[myButton]-2-|", options: [], metrics: nil, views: ["myButton": myButton])) 
titleBarView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-1-[myButton]-3-|", options: [], metrics: nil, views: ["myButton": myButton])) 

具有自動佈局,你不需要硬編碼按鈕的框架。即使您調整窗口大小,它總是在標題欄的右側。

相關問題