NSStatusBarButton keep highlighted

后端 未结 9 2400
一个人的身影
一个人的身影 2020-12-16 16:05

As of OS X 10.10 most of NSStatusItem has been deprecated in favour of the button property, which consists of an NSStatusBarButton. It should work like a norma

9条回答
  •  借酒劲吻你
    2020-12-16 16:40

    Luke’s answer is great. I’m just sharing my implementation based on that.

    NSButton *button = [[NSButton alloc] initWithFrame:self.statusItem.button.frame];
    button.alphaValue = 0;
    NSArray *array = @[self.statusItem.button, button];
    self.statusItem.button.superview.subviews = array;
    
    [button sendActionOn:(NSLeftMouseDownMask | NSRightMouseDownMask)];
    button.target = self;
    button.action = @selector(statusItemClicked);
    

提交回复
热议问题