且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在扩展坞中的应用程序中添加菜单?

更新时间: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.

  1. 启动界面生成器.
  2. 为菜单创建一个新的nib文件.
  3. 创建一个包含要添加到菜单中的项目的菜单.
  4. 将文件所有者的 dockMenu 出口(默认为 NSApplication )连接到菜单.
  5. 使用键 AppleDockMenu 将笔尖名称添加到 Info.plist 中.指定的笔尖名称不带扩展名.
  1. Launch Interface Builder.
  2. Create a new nib file for your menu.
  3. Create a menu that includes the items you wish to add to the menu.
  4. Connect the dockMenu outlet of the file’s owner (which by default is NSApplication) to your menu.
  5. Add the nib name to the 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.

(来源: 查看全文