NSStatusBarButton keep highlighted

后端 未结 9 2421
一个人的身影
一个人的身影 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:39

    TL;DR: Any NSButton instance (with NSImage that has template=YES) inside NSStatusItem property visually looks exactly like NSStatusBarButton. You can control their highlight property as you want.

    If you want to control highlight of your NSStatusItem manually and at the same time get all appearance benefits from using NSStatusBarButton you can use slightly different approach. You can create your own NSButton instance which has its own property highlight that is completely under your control. Then you have to create NSImage instance and set its template property to YES. Then you have to add this button to [NSStatusItem view] (yes, which is softly deprecated) or even as subview to system created [NSStatusItem button]. After this you have to draw background of NSStatusItem manually with [NSStatusItem drawStatusBarBackgroundInRect:withHighlight:] (which is also deprecated, oh).

    With this approach, you can combine full control of look and feel of your NSStatusItem and get automatic styling of button's image.

提交回复
热议问题