如何在Mac应用程序中使用自定义字体? [英] How to use custom fonts in a mac application?

查看:345
本文介绍了如何在Mac应用程序中使用自定义字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的swift应用程序中使用自定义字体,但是这些字体不会加载.

I try to use custom fonts in my swift app, but they don't load.

我将fonts.ttf复制到资源文件夹中,并在应用程序提供的字体"键下的Info.plist中添加了名称.

I copy the fonts.ttf in my resources folder, and I added the names in Info.plist under "Fonts provided by application " key.

我尝试使用.plist中的应用程序字体资源路径"键,但没有结果. 这是我用来应用字体的代码.我尝试使用:"MyFont.ttf"和"MyFont"

I've try with "Application fonts resource path" key from .plist , but no results. Here is the code I used to apply my font. I've try with : "MyFont.ttf" , and "MyFont"

@IBOutlet weak var label:NSTextField!

override func awakeFromNib() {
    label.font = NSFont(name: "MyFont.ttf", size: 15)
}

推荐答案

首先将要嵌入到OSX应用程序中的所需字体添加到项目中:

First add the desired font you want to embed to your OSX app to your project:

然后单击项目>信息,然后单击加号并添加新的键应用程序字体资源路径",然后在此处键入字体名称,以创建字符串数组:

Then click project > Info, then click the plus sign and add a new key "Application fonts resource path" and type the name of your fonts there creating an array of strings:

现在您可以选择自定义字体,字体名称将显示在此处,您仍然需要使用字体书"使其在Xcode中可用.

Now you can select custom font and the name of the font will show there, you still need to use the Font Book to make it available inside Xcode.

这篇关于如何在Mac应用程序中使用自定义字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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