Can anyone recommend a tutorial for making a Menulet? There are loads all over Google, however, many of them are from years back and while they're all sorta similar, I'm running into problems because some code has been deprecated since then.
Of course...
Well in this case I'm actually having more trouble with interface builder. I can't connect the delegate to the menu. I can do the Window though.
- (void)addSeparatorItem
{
[self addItem:[NSMenuItem separatorItem]];
}
- (void)addItemWithTitle:(NSString *)title
{
NSMenuItem *item;
item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:title
action:NULL
keyEquivalent:@""];
[self addItem:item];
[item release];
}
- (void)addItemWithTitle:(NSString *)title selector:(SEL)selector
{
NSMenuItem *item;
item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:title
action:selector
keyEquivalent:@""];
[self addItem:item];
[item release];
}
- (void)addItemWithTitle:(NSString *)title image:(NSImage *)image
{
NSMenuItem *item;
item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:title
action:NULL
keyEquivalent:@""];
item.image = image;
[self addItem:item];
[item release];
}
- (void)addItemWithTitle:(NSString *)title indentationLevel:(NSInteger)indentationLevel
{
NSMenuItem *item;
item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:title
action:NULL
keyEquivalent:@""];
item.indentationLevel = indentationLevel;
[self addItem:item];
[item release];
}
Hm. Personally, I just make the entire menu / menu UI in code. Making menus with icons, text, actions, and submenus in code is pretty trivial.
For Battery Status, I had a category on NSMenu that made adding that kind of stuff even more trivial. Here's some of the methods from it that I'll probably reuse in future projects (Battery Status supports pretty old Macs, thus why I have calls to release in here instead of just relying on ARC):
Code:snip
I hope those help.