How would you make the status header an image rather than text?
I have created a status item (menu item) for my application, but at the moment this is the title is the text, how could I show it an image?
This is the piece of code that sets the header. What do I need to change to this code to make it display the image?
[item setTitle:@"MenuItem"];
a source to share
You use the setImage: method , supplying it with NSImage
whatever you want to display on the menu bar.
Note that you may have a NSStatusItem
displaying image and text, for example, with a battery indicator.
Here's a small example defining an image in a file named OtherImage.jpg
:
NSImage *statusItemImage = [NSImage imageNamed:@"OtherImage"];
if( !statusItemImage ) {
NSLog(@"ERROR: Could not load the image for 'OtherImage.png'");
} else {
[item setImage:statusItemImage];
}
Make sure the OtherImage.png file is actually added to your Xcode project and copied to your application directory Resources
. If your image is not loading, it means that the file is not named correctly, not actually an image, or not in the application.
a source to share