如何设置NSMenu / NSMenuItems的字体? [英] How to set the font of NSMenu/NSMenuItems?

查看:193
本文介绍了如何设置NSMenu / NSMenuItems的字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚如何设置我的NSMenuItems在我的NSMenu的字体/样式。我尝试在NSMenu的setFont方法,但它似乎没有任何影响菜单项。 NSMenuItem似乎没有setFont方法。我希望他们都有相同的字体/样式,所以我希望只有一个属性我可以设置某处。

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.

推荐答案

他们可以有一个归属的标题,所以你可以设置一个属性字符串作为标题与所有的归因,字体包括:

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];

这篇关于如何设置NSMenu / NSMenuItems的字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆