替代 NSStatusItem.button (NSStatusBarButton) OSX 10.9

Alternative to NSStatusItem.button (NSStatusBarButton) OSX 10.9

我正在构建一个带有状态栏按钮的应用程序,我正在使用 NSPopover 在它上面显示一个视图。执行此操作的代码如下所示:

popover.showRelativeToRect(button.bounds, ofView: button, preferredEdge: NSRectEdge.MinY)

我想在 OSX 10.9 中实现同样的功能。该按钮在 < 10.10 时不可用。我查看了源代码,我发现我需要的大部分属性都在那里,我只需要一种方法来模拟按钮边界,并在这一点上查看。怎么可能呢?

完全替换 NSStatusItem.button 的建议也非常有用。

在 Mavericks 中使用已弃用的 NSStatusItem 实现。

这是界面:

@interface NSStatusItem (NSStatusItemDeprecated)

/* 
 These are softly deprecated methods of NSStatusItem.
 Their past and current behavior is to forward their calls onto the button property.
 They will be formally deprecated in a later release. 
 */
@property (nullable) SEL action;
@property (nullable) SEL doubleAction;
@property (nullable, weak) id target;
@property (nullable, copy) NSString *title;
@property (nullable, copy) NSAttributedString *attributedTitle;
@property (nullable, strong) NSImage *image;
@property (nullable, strong) NSImage *alternateImage;
@property (getter=isEnabled) BOOL enabled;
@property BOOL highlightMode;
@property (nullable, copy) NSString *toolTip;
- (NSInteger)sendActionOn:(NSInteger)mask;

/*
 Custom views should not be set on a status item.
 The button property with a template image will allow proper styling of the status item in various states and contexts and should be used instead.
 */
@property (nullable, strong) NSView *view;
- (void)drawStatusBarBackgroundInRect:(NSRect)rect withHighlight:(BOOL)highlight;
- (void)popUpStatusItemMenu:(NSMenu*)menu;

@end