如何使用下拉菜单实现工具栏按钮? [英] How to implement a toolbar button with drop down menu?
问题描述
以下图片是邮件"应用工具栏的一部分的屏幕截图.标志按钮显然是带有下拉菜单的NSSegmentedCell按钮.我希望按钮在单击图标部分时具有标准的动作,并且在单击V形时会下拉菜单.有标准的方法吗?我使用了2段NSSegmentedButton可以实现我想要的大多数功能,但是当我将菜单分配给第二段时,我无法显示人字形图标.
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.
如果有该V形字形的系统模板,我可以使其工作.除了自己绘制以外,还有其他方法可以得到吗?
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?
推荐答案
事实证明,NSSegmentedControl提供了setShowsMenuIndicator
,它像NSPopupButton一样为段绘制了向下的V形.不幸的是,仅从macOS 10.13起可用.
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.
这篇关于如何使用下拉菜单实现工具栏按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!