带有静态图像的弹出按钮(Cocoa OSX) [英] A popup button with a static image (Cocoa OSX)

查看:245
本文介绍了带有静态图像的弹出按钮(Cocoa OSX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个弹出按钮,总是显示一个+作为其图像,当你点击它,弹出一个上下文菜单,将允许你决定你要添加的对象的类型。是否还有使用NSPopupButton做到这一点?我在NSPopupButotn的规范中看到,SetImage方法没有效果,所以看起来这可能不会使用这个类工作。它是否正确?

解决方案

是的, NSPopUpButton 的外观是错误的



你想要的是一个附有菜单的常规 NSButton 。在Interface Builder中,清除标题,将Bezel设置为Square,将Position设置为中心图标版本,将图像设置为 NSAddTemplate



然后创建一个 NSPopUpButton ,设置为下拉,隐藏,并将其对齐/设置其大小到NSButton的底部。最后,将 NSButton 中的 performClick:连接到 performClick: NSPopUpButton



点击按钮;因为你必须编写一些代码来使用(非绘图) NSPopUpButtonCell


I am trying to make a popup button that always displays a + as its image and when you click on it, a context menu pops up that will allow you to decide what type of object you want to add. Is there anyway to do this using an NSPopupButton? I saw in the specs for NSPopupButotn that the method SetImage has no effect so it seems that this is likely not going to work using this class. Is this correct?

解决方案

Yes, the visible appearance of NSPopUpButton is wrong for what you want.

What you want is a regular NSButton with a menu attached. In Interface Builder clear the title, set the Bezel to Square, the Position to the center icon-only version and the image to NSAddTemplate.

Then create a NSPopUpButton, set it to "Pull Down", hidden, and align it/set its size to the bottom of the NSButton.

Finally, connect performClick: in the NSButton to performClick: on the NSPopUpButton.

That won't handle a click-hold on the button; for that you'll have to write some code to use a (non-drawing) NSPopUpButtonCell.

这篇关于带有静态图像的弹出按钮(Cocoa OSX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆