简体   繁体   English

如何获得可可中给定字体家族的受支持的字体

[英]How do i get the supported typefaces for a given font family in cocoa

I have a font family popup button which lets the user select a font. 我有一个字体系列弹出按钮,可让用户选择字体。 I also have corresponding font face popup button and a font size combo button in my UI. 我的UI中也有相应的字体弹出按钮和字体大小组合按钮。 When a user changes the font family, I want to update the font face popup button's menu with the supported faces/traits for that font family. 当用户更改字体系列时,我想使用该字体系列支持的字体/特征来更新字体外观弹出按钮的菜单。 Could someone please let me know how this is done. 有人可以让我知道这是怎么做的。

TextEdit seems to do it and I could not figure out how. TextEdit似乎可以做到,但我不知道怎么做。 I have attached a screenshot of the textedit toolbar font popups. 我已附上了textedit工具栏字体弹出窗口的屏幕截图。 I want to mimic these controls in my app. 我想在我的应用中模仿这些控件。

在此处输入图片说明

Use -[[NSFontManager sharedFontManager] availableMembersOfFontFamily:] to get an array of font descriptions (not instances of NSFont ) in the specified font family. 使用-[[NSFontManager sharedFontManager] availableMembersOfFontFamily:]获取指定字体系列中的字体描述数组(不是NSFont实例)。 If you have a font already and want its font family, use -[NSFont fontFamily] . 如果您已经有一种字体并且想要它的字体系列,请使用-[NSFont fontFamily]

For the specific format of the returned array, see the documentation for NSFontManager . 有关返回数组的特定格式,请参见NSFontManager 的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM