可以程序化高亮的自定义状态项视图。
NSStatusItem
只有在被点击时才能高亮。
如果您想程序化显示原始弹出菜单,这是一个问题。
QBStatusItemView可以设置到NSStatusItem
的view
属性,并且可以程序化高亮。
因此,它对于使用原始弹出菜单而不是NSMenu
的App非常有用。
在您的项目中导入#import "QBStatusItemView.h"
。
NSStatusItem *statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
statusItem.image = [NSImage imageNamed:@"status_icon"];
statusItem.alternateImage = [NSImage imageNamed:@"status_icon_highlighted"];
QBStatusItemView *statusItemView = [[QBStatusItemView alloc] init];
statusItemView.delegate = self;
statusItem.view = statusItemView;
当视图被激活和取消激活时,代理会收到通知。
#pragma mark - QBStatusItemViewDelegate
- (void)statusItemViewDidActivate:(QBStatusItemView *)statusItemView
{
NSLog(@"*** statusItemViewDidActivate:");
}
- (void)statusItemViewDidDeactivate:(QBStatusItemView *)statusItemView
{
NSLog(@"*** statusItemViewDidDeactivate:");
}
Katsuma Tanaka,[email protected]
QBStatusItemView可用MIT许可证。有关更多信息,请参阅LICENSE文件。