objective c - How to add icons in os x status bar menus (left from text) -


i want add icons on left side of status bar menus text in os x. cannot find sample code implement in code. right using code set image status bar (below) , ibactions call applescript files.

    - (void)awakefromnib {      statusitem = [[[nsstatusbar systemstatusbar] statusitemwithlength:nsvariablestatusitemlength] retain];      nsbundle *bundle = [nsbundle mainbundle];      statusimage = [[nsimage alloc] initwithcontentsoffile:[bundle pathforresource:@"wifi1" oftype:@"png"]];     statushighlightimage = [[nsimage alloc] initwithcontentsoffile:[bundle pathforresource:@"wifi2" oftype:@"png"]];      [statusitem setimage:statusimage];     [statusitem setalternateimage:statushighlightimage];     [statusitem setmenu:statusmenu];     [statusitem sethighlightmode:yes]; }  - (void)dealloc {      [statusimage release];     [statushighlightimage release];     [super dealloc]; }  - (ibaction)remoteappleevents:(id)sender {      nsstring* path = [[nsbundle mainbundle] pathforresource:@"appleevents" oftype:@"scpt"];     nsurl* url = [nsurl fileurlwithpath:path];nsdictionary* errors = [nsdictionary dictionary];     nsapplescript* applescript = [[nsapplescript alloc] initwithcontentsofurl:url error:&errors];     [applescript executeandreturnerror:nil];     [applescript release]; }  - (ibaction)internetsharing:(id)sender {      nsstring* path = [[nsbundle mainbundle] pathforresource:@"wifishare" oftype:@"scpt"];     nsurl* url = [nsurl fileurlwithpath:path];nsdictionary* errors = [nsdictionary dictionary];     nsapplescript* applescript = [[nsapplescript alloc] initwithcontentsofurl:url error:&errors];     [applescript executeandreturnerror:nil];     [applescript release]; }  - (ibaction)bluetoothsharing:(id)sender {      nsstring* path = [[nsbundle mainbundle] pathforresource:@"bluetooth" oftype:@"scpt"];     nsurl* url = [nsurl fileurlwithpath:path];nsdictionary* errors = [nsdictionary dictionary];     nsapplescript* applescript = [[nsapplescript alloc] initwithcontentsofurl:url error:&errors];     [applescript executeandreturnerror:nil];     [applescript release]; } 

any appreciated. thanx!

update*

my drop down menu in ib

my drop down menu in ib.

updated answer:

to set icon in nsmenuitem or nsmenu this:

enter image description here

you have add image project , set menus image in "attribute inspector"

enter image description here

if want set image programatically:

give each menu item outlet , use

setimage:

as have done status bar

 bar = [nsstatusbar systemstatusbar]; statusitem =  [bar statusitemwithlength: nsvariablestatusitemlength]  ;   statusimage = [nsimage imagenamed:@"status.icns"];     statushighlightimage = [nsimage imagenamed:@"statushighlight.icns"];  [statusitem setimage:statusimage]; [statusitem setalternateimage:statushighlightimage];  [statusitem setmenu:_statusmenu]; [statusitem sethighlightmode:yes];  menu1image = [nsimage imagenamed:@"login.icns"]; menu2image = [nsimage imagenamed:@"persist.icns"]; menu3image = [nsimage imagenamed:@"thumbicon_.png"];  [_menuitem1 setimage:menu1image]; [_menuitem2 setimage:menu2image]; [_menuitem3 setimage:menu3image]; 

enter image description here

also code take account arc


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -