Search code examples
objective-ccocoansmenuitemnsmenu

NSMenuItem height?


How can I change the height of an NSMenuItem? When I change the font of a menu, an NSMenuItem automatically resizes to just fit the title, leaving no space above or below the title. It looks very cramped.

Looks like this:

enter image description here

Want it to look like this:

enter image description here

I've tried a million tweaks related to the attributed title of the menu items, but to no avail. I also don't want to use the view property of the menu items because I want to keep the highlight. Any other ideas?

Edit: This is what I'd like (more or less), but based on NSMenu, not redoing it from the ground up.

enter image description here


Solution

  • You can set an empty 1-pixel wide image with the desired height:

    NSImage *image=[[NSImage alloc]initWithSize:NSMakeSize(1,30)];
    
    [menuItem setImage:image];
    

    Obviously you end up with titles that are offset 1 pixel to the right, though that may be acceptable if uniformly applied.