简体   繁体   English

如何从磁盘加载字体?

[英]How to load font from disk?

Is it possible to load a font from disk and use it during run-time? 是否可以从磁盘加载字体并在运行时使用它?

If so, how/where do you store the fonts on the iphone/ipod/ipad for your app to use? 如果是这样,如何将字体存储在iphone / ipod / ipad上以供应用使用?

(To be clear, I'm not talking about adding the font as a resource at design-time. I'm asking about a way to allow a user to select a font file during run-time, loading it, and making it available for use.) (要清楚,我并不是在设计时就将字体作为资源添加。我在问一种允许用户在运行时选择字体文件,加载它并使之可用的方法。用来。)

您应该将它们(.ttf,.otf)放入UIAppFonts下的信息UIAppFonts然后可以通过setFont: withSize: “使用”它们setFont: withSize:

You add your font as a resource, add it to your info.plist under Fonts provided by application ( UIAppFonts ) array, then use it as any embedded one. 您将字体添加为资源,将其添加到Fonts provided by applicationUIAppFonts )数组下的info.plist中,然后将其用作任何嵌入式Fonts provided by application


Ok, in that case take a look at FontLabel project. 好的,在这种情况下,请看一下FontLabel项目。

One thing though, looking through it's code - you can only get CGFontRef and with kind of voodoo work with it, no conversion between CGFontRef and UIFont really exists. 不过,有一件事,仔细检查一下它的代码-您只能获得CGFontRef,并且通过某种伏都教工作,实际上不存在CGFontRef和UIFont之间的转换。 See this question 看到这个问题

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

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