gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 18:04:37 26 4
gpt4 key购买 nike

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

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

问候,

达纳拉吉。

最佳答案

这是一个 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];

关于cocoa - 如何创建具有延迟 NSMenu 的 NSButton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3309030/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com