反向工程状态栏项目的NSMenu [英] Reverse engineering an NSMenu for a Status Bar Item

查看:117
本文介绍了反向工程状态栏项目的NSMenu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为Tapbot的PastebotSync应用程序中创建的状态栏项目创建菜单:

I'm want to create a menu for a status bar item like the one seen in Tapbot's PastebotSync application:

有没有人有任何想法如何实现在菜单顶部的自定义区域

Does anyone have any ideas how to achieve the custom area at the top of the menu which is flush with the top?

任何人都有更好的想法或建议吗?

Anyone have any better ideas or suggestions?

谢谢!

推荐答案

我发布了一个解决方案,在 NSMenuItem自定义视图之上的间隙。

In case anyone comes looking, I posted a solution to this at Gap above NSMenuItem custom view.

以下是代码:

@interface FullMenuItemView : NSView
@end

@implementation FullMenuItemView
- (void) drawRect:(NSRect)dirtyRect
{
    NSRect fullBounds = [self bounds];
    fullBounds.size.height += 4;
    [[NSBezierPath bezierPathWithRect:fullBounds] setClip];

    // Then do your drawing, for example...
    [[NSColor blueColor] set];
    NSRectFill( fullBounds );
}
@end

使用方法如下:

CGFloat menuItemHeight = 32;

NSRect viewRect = NSMakeRect(0, 0, /* width autoresizes */ 1, menuItemHeight);
NSView *menuItemView = [[[FullMenuItemView alloc] initWithFrame:viewRect] autorelease];
menuItemView.autoresizingMask = NSViewWidthSizable;

yourMenuItem.view = menuItemView;

这篇关于反向工程状态栏项目的NSMenu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆