The triangle at the top looks so wonderful, but I can't compose one like that.
顶部的三角形看起来很精彩,但我不能那样构成一个。
I had tried to write some code as below, but I saw an ordinary menu.
我曾尝试编写如下代码,但我看到了一个普通的菜单。
- (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]; }
Please help me to do something to carry it out. Thanks a lot!
请帮我做点什么来实现它。非常感谢!
1 个解决方案
#1
1
- (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];
}
The parameter of popover callback is an instance of NSStatusBarButton class. Here is the output in my console.
popover回调的参数是NSStatusBarButton类的一个实例。这是我的控制台中的输出。
2013-01-20 23:08:36.602 TestMacWindow[1190:303] sender is: <NSStatusBarButton: 0x101917d10>
#1
1
- (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];
}
The parameter of popover callback is an instance of NSStatusBarButton class. Here is the output in my console.
popover回调的参数是NSStatusBarButton类的一个实例。这是我的控制台中的输出。
2013-01-20 23:08:36.602 TestMacWindow[1190:303] sender is: <NSStatusBarButton: 0x101917d10>