在"界面"构建器中,如何将自定义按钮添加到窗口标题栏?

Ste*_*eod 2 cocoa interface-builder nspanel

在我的OS X应用程序中,使用Interface Builder,我有一个如下所示的窗口:

在此输入图像描述

我想在右侧添加一个按钮,以实现此目的:

在此输入图像描述

如果可以,我该怎么办?

Ano*_*dya 6

它不可能与Interface Builder一起使用,但是您可以通过一点点编码来完成它:

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.
Run Code Online (Sandbox Code Playgroud)