Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 589
JPC Avatar asked Nov 19 '12 17:11

JPC


1 Answers

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];
like image 133
Ramy Al Zuhouri Avatar answered Oct 13 '22 20:10

Ramy Al Zuhouri