显示菜单的公开按钮
请给我一个建议,如何实现这种披露按钮,如我的屏幕截图所示 - 一个披露“向下箭头”按钮,点击时显示一个菜单:
我尝试了两种方法,使用 NSPopupButton
和 NSButton
以及公开样式和手动菜单显示:
NSPopupButton< /代码> 保留显示默认值文本,并且无法在 Interface Builder 中将其调整为较窄的尺寸。
NSButton
显示菜单,但它显然错位到我单击的位置按钮,而不是在底部边缘。我正在使用以下代码:- (IBAction)handleShowMenu:(id)sender { [NSMenu popUpContextMenu:profileMenu withEvent:[NSApp currentEvent] forView:发件人]; }
那么显示这样的菜单的正确方法是什么?
Please give me an advice how to implement this kind of disclosure button as on my screenshot - a disclosure "arrow down" button displaying a menu on click:
I've tried two approaches, using NSPopupButton
and NSButton
with disclosure style and manual menu displaying:
NSPopupButton
keeps displaying default value text and can't be resized in Interface Builder to a narrow size.NSButton
displays a menu, but it's obviously misplaced to the point where I click the button, not at the bottom edge. I'm using the following code:- (IBAction)handleShowMenu:(id)sender { [NSMenu popUpContextMenu:profileMenu withEvent:[NSApp currentEvent] forView:sender]; }
So what's the right way to display such a menu?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经成功了!正确的设置是使用带有“无箭头”和“披露”边框样式的
NSPopupButton
,“瞬时推入 >”类型。I've managed with it! The correct setup is to use
NSPopupButton
with "No Arrow" and "Disclosure" bezel style, "Momentary Push In" type.将弹出按钮的边框样式更改为“纹理”并将箭头更改为“中心”将为您提供第一个屏幕截图的外观。如果您不想显示所选项目的标题,还需要将“位置”设置为“仅图像”(白色方块)。
编辑:我在 IB 3 中尝试过这个并且只模拟了界面。看起来“Textured”样式在 Xcode 4 中看起来有所不同。“Round Textured”很接近,但它不会使三角形水平居中。
Changing the bezel style of your popup button to "Textured" and the arrow to "Center" will give you the appearance of your first screenshot. If you don't want the title of the selected item to appear, you also need to set the "Position" to "image only" (the white square).
Edit: I tried this in IB 3 and only simulated the interface. It seems that the "Textured" style looks different in Xcode 4. "Round Textured" is close, but it doesn't center the triangle horizontally.