简体   繁体   中英

How to disable highlighted mode of NSStatusItem

I'd like to set disable highlighted mode of NSStatusItem when clicked. In OS X 10.10 and later version, highlightedMode property has been deprecated, and Apple suggest using button property. So, what's the equivalent of setHighlightedMode: ? Swift or Objective-C is OK.

Thanks in advance.

Get the button's cell, cast as an NSButtonCell* , and set its highlightsBy property to 0. Of course, that involves cells, which are also being gradually deprecated.

Internally, -[NSStatusItem setHighlightMode:] calls -[NSStatusBarButton setHighlightMode:] , which calls -[NSStatusBarButtonCell setHighlightMode:] . That last calls -setHighlightsBy: on itself with either 0 or NSContentsCellMask | NSChangeBackgroundCellMask NSContentsCellMask | NSChangeBackgroundCellMask , depending on the mode. Unfortunately, neither -[NSStatusBarButton setHighlightMode:] nor NSStatusBarButtonCell are public API, so the best you can do is emulate them.

All told, it's probably best to just keep using -[NSStatusItem setHighlightMode:] and file a bug report with Apple requesting a non-deprecated approach.

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