2

ここに画像の説明を入力してください

一番上の三角形はとても素敵に見えますが、私はそのような三角形を作成することはできません。

以下のようなコードを書いてみましたが、普通のメニューが見えました。

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {// Insert code here to initialize your application

NSStatusItem * statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:110] retain];
[statusItem setTitle:@"Test"];
[statusItem setEnabled:YES];
[statusItem setHighlightMode:YES];

statusItem.menu = [[NSMenu alloc] initWithTitle:@"menu"];
NSMenuItem * menuItem = [[NSMenuItem alloc] initWithTitle:@"menuItem1" action:NULL keyEquivalent:@""];
[statusItem.menu addItem:menuItem]; }

ここに画像の説明を入力してください

それを実行するために私が何かをするのを手伝ってください。どうもありがとう!

4

1 に答える 1

2
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
// Insert code here to initialize your application

NSStatusItem * statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:110] retain];
[statusItem setTitle:@"Test"];
[statusItem setEnabled:YES];
[statusItem setHighlightMode:YES];
[statusItem setTarget:self];
[statusItem setAction:@selector(showPopover:)];
}

- (void) showPopover:(id)sender {
NSLog(@"sender is: %@", sender);
RSTestPopoverViewController * viewController = [[RSTestPopoverViewController alloc] initWithNibName:@"RSTestPopoverViewController" bundle:nil];
NSPopover * popover = [NSPopover new];
popover.contentViewController = viewController;
[popover showRelativeToRect:NSZeroRect ofView:(NSView *)sender preferredEdge:NSMinYEdge];
}

ポップオーバーコールバックのパラメーターは、NSStatusBarButtonクラスのインスタンスです。これが私のコンソールの出力です。

2013-01-20 23:08:36.602 TestMacWindow[1190:303] sender is: <NSStatusBarButton: 0x101917d10>
于 2013-01-20T15:08:58.650 に答える