Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement a toolbar button with drop down menu?

Tags:

macos

cocoa

The following picture is a screenshot of part of Mail app’s toolbar. The flag button is apparently an NSSegmentedCell button with a drop down menu. I want the button to have a standard action when clicked on the icon part, and a menu to drop down when the chevron is clicked. Is there a standard way to do it? I used a 2 segment NSSegmentedButton that achieves most of what I want, but I can’t get the chevron icon to show when I assign a menu to the second segment.

Edit: I could make it work if there was a system template for that chevron. Is there any other way to get it other than drawing it myself?

enter image description here

like image 915
sbenitezb Avatar asked Jan 24 '26 21:01

sbenitezb


1 Answers

It turns out NSSegmentedControl provides setShowsMenuIndicator that draws the down chevron for a segment just like an NSPopupButton. Unfortunately, it’s only available from macOS 10.13 onwards.

like image 70
sbenitezb Avatar answered Jan 26 '26 13:01

sbenitezb