Search code examples
objective-ccocoainterface-buildernsmenuitemnsmenu

How to set the font of NSMenu/NSMenuItems?


I can’t figure out how to set the font/styling of my NSMenuItems in my NSMenu. I tried the setFont method on the NSMenu but it doesn’t seem to have any effect on the menu items. NSMenuItem doesn’t seem to have a setFont method. I would like for them all to have the same font/style so I would hope there’s just one property I can set somewhere.


Solution

  • They can have an attributed title, so you can set an attributed string as title with all it's attributed, font included:

    NSMutableAttributedString* str =[[NSMutableAttributedString alloc]initWithString: @"Title"];
    [str setAttributes: @{ NSFontAttributeName : [NSFont fontWithName: @"myFont" size: 12.0] } range: NSMakeRange(0, [str length])];
    [label setAttributedString: str];