将按钮添加到Mac窗口的系统范围标题栏 [英] Add buttons to Mac window Title Bars, system-wide

查看:179
本文介绍了将按钮添加到Mac窗口的系统范围标题栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在在Mac上打开的所有窗口的rel ="nofollow noreferrer">标题栏.

I want to be able to add a button to the title bar of all windows that open on a Mac.

该按钮将位于右侧,与X - +按钮相对.

The button will go on the right hand side, opposite the X - + buttons.

在此处询问有关我的应用程序的窗口的窗口:
如何在以下位置创建优胜美地风格的统一工具栏界面生成器?

This is asked about windows of my app here:
How can I create Yosemite-style unified toolbar in Interface Builder?

但是我希望按钮显示在在Mac上打开的所有应用的所有窗口中.显然,只有在用户安装了该程序后,这种情况才会发生.

But I want the button to appear on all windows, of any app, that are opened on the Mac. Obviously, this will only happen once the user has installed this program.

我知道这实际上是插入"操作系统的UI,但是我看到其他应用程序也这样做,这使我觉得它是可行的.

I understand that this is essentially "plugging into" the OS's UI, but I have seen other apps do this, which makes me feel that it is do-able.

这是我想要按钮的屏幕截图:

Here is screenshot where I want the button:

推荐答案

这实际上是一个分为两部分的问题.至于如何在此处设置按钮,我建议使用-[NSWindow standardWindowButton:]来获取现有的窗口按钮及其超级视图(即标题栏):

This is really a two-part question. As for how to get a button up there, I’d suggest using -[NSWindow standardWindowButton:] to get an existing window button and its superview (i. e. the title bar):

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.

作为 SIMBL 插件,该插件可能最容易实现.

The plugging-in is probably easiest to do as a SIMBL plug-in.

这篇关于将按钮添加到Mac窗口的系统范围标题栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆