How do I create an NSMenuItem view for a menu item with an embedded NSProgressIndicator?

I would like to create a menu item with a built-in NSProgressIndicator

, similar to the "Wi-Fi: Search for networks ..." menu item in the Wi-Fi status menu:

Screenshot of opened Wi-Fi status menu on Mac showing "Wi-Fi: Looking for Networks…" menu item

I think I will need to use the method setView:

as discussed in: Views in Menu Items . However, when I call setView:

and pass NSProgressIndicator

, only is displayed NSProgressIndicator

.

How do I create a custom menu item to get the same result as the "Wi-Fi: Search for networks ..." menu item in the Wi-Fi status menu?

+3


source to share


1 answer


As stated in the doc you linked to:

A menu item with a view does not display its title, state, font, or other standard drawing attributes and assigns complete design responsibility.

So, if you want your menu item to look like a regular menu item as well as some other stuff, your view should draw regular menu items in addition to other stuff. This way you can customize the presentation of the menu item to a custom view. The progress bar will be one of the subclasses of this custom view, but you will need different subqueries for other functions. For example, a text box for the text of a menu item and an image view for a status indicator (if your element is showing a status).



You will need to highlight the selection as the item is selected or tracked. You will also need to track your mouse. Apple has some sample code that demonstrates the various parts of this:

MenuItemView
CustomMenus
GridMenu

+4


source







All Articles