2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ステータスメニューの表示

Posted at
AppDelegate.c
# import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;

@end
AppDelegate.m
# import "AppDelegate.h"

@interface AppDelegate () // クラスエクステンション?

@property (weak) IBOutlet NSMenu *statusMenu;

@end

@implementation AppDelegate{
    NSStatusItem* _statusItem;  // ステータスバーに表示されるアイテム
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [self setupStatusItem];  // setupStatusItemメソッドの実行
}

- (void)setupStatusItem
{
    NSStatusBar *systemStatusBar = [NSStatusBar systemStatusBar];  // ステータスバー
    _statusItem = [systemStatusBar statusItemWithLength:NSVariableStatusItemLength];
    [_statusItem setHighlightMode:YES];  // ステータスバーに表示されるメニュー
    [_statusItem setTitle:@"StatusBarApp"];  // ステータスバーに表示されるメニューのタイトル
    [_statusItem setImage:[NSImage imageNamed:@"StatusBarIconTemplate"]];  // ステータスバーに表示されるメニューのアイコン画像
    [_statusItem setMenu:[self statusMenu]];  // メニューをセットする
}

@end
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?