以编程方式为 NSStatusBar.systemStatusBar 创建 NSMenu
我正在尝试仅使用代码在系统状态栏中创建一个简单的菜单。我没有收到任何编译或运行时错误,但我看不到任何效果。
- (void)awakeFromNib
{
NSMenu *stackMenu = [[NSMenu alloc] initWithTitle:@"Status Menu"];
NSMenuItem *soMenuItem =
[[NSMenuItem alloc] initWithTitle:@"Status Menu Item" action:nil keyEquivalent:@"S"];
[soMenuItem setEnabled:YES];
[stackMenu addItem:soMenuItem];
statusItem = [[[NSStatusBar systemStatusBar]
statusItemWithLength:NSVariableStatusItemLength]
retain];
[statusItem setMenu:stackMenu];
}
I'm trying to create a simple menu in the System Status Bar using code only. I'm not receiving any compilation or runtime errors but I see no effect at all.
- (void)awakeFromNib
{
NSMenu *stackMenu = [[NSMenu alloc] initWithTitle:@"Status Menu"];
NSMenuItem *soMenuItem =
[[NSMenuItem alloc] initWithTitle:@"Status Menu Item" action:nil keyEquivalent:@"S"];
[soMenuItem setEnabled:YES];
[stackMenu addItem:soMenuItem];
statusItem = [[[NSStatusBar systemStatusBar]
statusItemWithLength:NSVariableStatusItemLength]
retain];
[statusItem setMenu:stackMenu];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不相信
NSStatusItem
会隐式地采用与其关联的NSMenu
的title
(这就是我猜测你想要的发生。)尝试显式设置NSStatusItem
的title
(和/或其image
)。前任
I don't believe the
NSStatusItem
will implicitly take on thetitle
of theNSMenu
associated with it (which is what I am guessing you want to happen.) Try explicitly setting theNSStatusItem
'stitle
(and/or itsimage
).e.x.