【发布时间】:2014-11-17 20:40:26
【问题描述】:
我正在尝试制作一个状态栏项目,比如右上角的电池或时间机器指示器。我的代码如下
- (void)activateStatusBarItem:(id)object{
NSStatusBar *systemBar = [NSStatusBar systemStatusBar];
NSStatusItem *theItem = [systemBar statusItemWithLength:NSVariableStatusItemLength];
NSImage *statusBarIcon = [NSImage imageNamed:@"icon-sleep.png"];
statusBarIcon.size = CGSizeMake(NSSquareStatusItemLength, NSSquareStatusItemLength);
[theItem setImage:statusBarIcon];
[theItem setTitle:@"abc"];
[theItem setTarget:self];
[theItem setAction:@selector(showHUD:)];
}
应用启动时调用此方法。但是,我没有在菜单上看到 theItem。它确实工作过一次,没有图像的相同代码。
此外,当我查看 Apple 的方法时: - 设置标题: - 设置图像: - 设定目标: - 设置动作: 都说同时可用和折旧,看下图。有没有其他方法,我可以做到这一点。我希望在单击项目时显示一个窗口/面板,可能附加到栏上。
【问题讨论】: