iOS中的动态自定义字体加载器 [英] Dynamic custom fonts loader in iOS

查看:113
本文介绍了iOS中的动态自定义字体加载器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经知道如何通过这里将自定义字体加载到我的iPhone应用程序中的项目
我想询问是否有办法从代码中执行此操作?我的问题是我的应用程序中有一个资源文件夹,我有一个字体文件名,我们称之为 myfont.ttf

i already know how to load a custom font to my project in iPhone App from here I want to ask if there is a way to do this from code? My problem is that I have a resource folder in my app, i have a font file name, lets call it "myfont.ttf".

我想获取一个ttf文件并将其放入plist文件 from code ,而且我还想知道 fontWithName:size:方法的显示名称。有办法实现这个目标吗?

I want to grab a ttf file and put it to plist file from code, and what's more i want to know the display name for fontWithName:size: method. There is a way to achieve this?

推荐答案

是的,你可以。但是你需要使用CoreText和/或CoreGraphics。

Yes you can. But you've to work a lot with CoreText and/or CoreGraphics.

Zynga的一个很好的课程可以帮助你做到这一点:$ b​​ $ b https://github.com/zynga/FontLabel

There's a nice class from Zynga that could help you in doing this: https://github.com/zynga/FontLabel

示例项目显示如何在不使用.plist的情况下从包中加载.ttf文件,并在应用程序中使用这些字体。

The example project shows how to load .ttf files from the bundle without using the .plist and use these fonts inside the application.

代码有效且是从开始就很好。

The code is valid and is a good point from start.

编辑:以前的方法使用CoreGraphics,这很好,但使用Core Text要好得多。
我找到了一个有趣的答案:如何使用核心文本从文件加载字体(TTF)?

The previous approach uses CoreGraphics, that is good, but use Core Text is much better. I found an interesting answer to this question: How can you load a font (TTF) from a file using Core Text?

如果您没有使用经验CoreText框架,请阅读里面的官方介绍Apple文档

If you don't have experience with CoreText framework, please read the official introduction inside the Apple documentation.

这篇关于iOS中的动态自定义字体加载器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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