更新时间:2023-11-29 23:08:16
使用Nib文件添加静态菜单项
如果您的应用程序需要在应用程序的"Dock"图块菜单中添加静态项,则可以在nib文件中提供这些项.为此,请执行以下步骤.
If your application needs to add static items to the application’s Dock tile’s menu, you can provide those items in a nib file. To do this, perform the following steps.
dockMenu
出口(默认为 NSApplication
)连接到菜单. AppleDockMenu
将笔尖名称添加到 Info.plist
中.指定的笔尖名称不带扩展名.dockMenu
outlet of the file’s owner (which by default is NSApplication
) to your menu.Info.plist
, using the key AppleDockMenu
. The nib name is specified without an extension.使用应用程序委托动态添加菜单项
应用程序还可以向应用程序的Dock磁贴菜单中动态提供项目.为此,您的应用程序的委托对象提供了一个 applicationDockMenu:
方法.此方法返回一个NSMenu对象,该对象提供要添加到菜单的所有自定义菜单项.如果您还提供了使用笔尖文件的菜单(请参见
An application can also provide items dynamically to your application’s Dock tile’s menu. To do this, your application’s delegate object provides a applicationDockMenu:
method. This method returns a NSMenu object that provides all the custom menu items you wish to add to the menu. If you also provided a menu using a nib file (see Adding Static Menu Items With a Nib File), any menu returned by your delegate replaces the menu provided in the nib file.
(来源: 查看全文