简体   繁体   中英

Is there any way to highlight the status bar item programmatically?

I'd like to perform the following:
when I click on the status bar item ( NSStatusItem ) I want to highlight it (no menu) indefinitely and when the application loses focus I want to stop highlighting it.

Is there any way of doing this? I can't find it, tbh.

You can probably do this with a custom view that sends the status item a drawStatusBarBackgroundInRect:withHighlight: message .

I doubt there's any way to do it without a custom view, since, as I mentioned in my comment on the question, keeping the item highlighted when the user doesn't have the mouse down on it looks bad.

Old question, but I think it is worth adding this alternative answer.

This will not automatically un-highlight when the application loses focus, but this allows you to highlight without using a custom view (as the other answer requires):

NSStatusItem *statusItem = [self getStatusItem];
[statusItem.button setHighlighted:YES];

You can unhighlight it manually using the same method:

[statusItem.button setHighlighted:NO];

Note I got this answer from a similar question here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM