如何创建具有延迟 NSMenu 的 NSButton?

发布于 2024-09-11 03:17:17 字数 162 浏览 2 评论 0原文

在 Cocoa 中,我想创建一个带有延迟菜单的 nsbutton。 即,当单击时,它应该调用操作方法,并且当保持按下状态 2 秒时,它应该显示一个 ns 菜单。

它类似于 Xcode 工具栏中的“Build Active Target”按钮。

问候,

达纳拉吉。

In Cocoa i want to create an nsbutton with delayed menu.
i.e., When clicked it should call the action method and when kept in pressed state for 2 seconds it should display a nsmenu.

It is similar to "Build Active Target" button present in Xcode toolbar.

Regards,

Dhanaraj.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅笑依然 2024-09-18 03:17:17

这是一个 NSPopUpButton.. 以下是我在应用程序中创建它的方法。

NSToolbarItem* item = [[[NSToolbarItem alloc] initWithItemIdentifier:identifier] autorelease];
[item setLabel:label];
[item setPaletteLabel:label];
[item setToolTip:tooltip];

NSPopUpButton* button = [[[NSPopUpButton alloc] initWithFrame:NSMakeRect(0, 0, 200, 24) pullsDown:NO] autorelease];
NSMenu* menu = [button menu];
// insert code here, that adds NSMenuItems to the menu

[button setTarget:self];
[button setAction:@selector(menuAction:)];
[[button cell] setBezelStyle:NSTexturedRoundedBezelStyle];
[[button cell] setArrowPosition:NSPopUpArrowAtBottom];
[[button cell] setFont:[NSFont systemFontOfSize:14]];
[item setView:button];

It's a NSPopUpButton.. Here is how I create it in my app.

NSToolbarItem* item = [[[NSToolbarItem alloc] initWithItemIdentifier:identifier] autorelease];
[item setLabel:label];
[item setPaletteLabel:label];
[item setToolTip:tooltip];

NSPopUpButton* button = [[[NSPopUpButton alloc] initWithFrame:NSMakeRect(0, 0, 200, 24) pullsDown:NO] autorelease];
NSMenu* menu = [button menu];
// insert code here, that adds NSMenuItems to the menu

[button setTarget:self];
[button setAction:@selector(menuAction:)];
[[button cell] setBezelStyle:NSTexturedRoundedBezelStyle];
[[button cell] setArrowPosition:NSPopUpArrowAtBottom];
[[button cell] setFont:[NSFont systemFontOfSize:14]];
[item setView:button];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文