快速自定义字体 [英] Custom Font in swift

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

问题描述

我的应用程序必须使用某些自定义字体,因此我开始通过将字体复制到应用程序文件夹中来添加字体,并在info.plist中创建应用程序提供的字体",在Mac上一切正常,但是当我开始在手机中调试字体,将字体恢复为系统字体,该如何解决?

My application has to use some custom font so I start to add the font by copy it to the application folder and create the "Fonts provided by application" in info.plist, everything work fine in my Mac but when I start to debug in my phone the font turn back to the system font, How can I fix this?

推荐答案

实际上,这很容易做到.首先,您需要确保字体文件在您的应用程序文件层次结构中:

This is pretty easy to do, actually. Firstly, you need to make sure that the font file is in your app file hierarchy:

您可以在此处看到"small_pixel.ttf"

you can see mine here "small_pixel.ttf"

第二,您需要确保info.plist文件的文件名完全是您的自定义字体:

Secondly you need to make sure that the info.plist file has the EXACT file name as your custom font:

您可以在这里看到.

第三,您需要确保该字体包含在bundle resources中,您可以通过以下方式导航到它:

Thirdly, you need to make sure that the font is included in bundle resources you can navigate to it by going:

要将其添加到bundle resources中,只需将文件拖放到层次结构中即可.

to add it to bundle resources simply drag and drop the file into the hierarchy.

最后,您可以通过...查看所有字体.

Finally you can see all of your fonts by doing...

for family: String in UIFont.familyNames()
{
    print("\(family)")
    for names: String in UIFont.fontNamesForFamilyName(family)
    {
        print("== \(names)")
    }
}

...在启动应用程序时会调用的某些函数中.只需在调试"区域中向下滚动,直到找到您的字体.

...in some function that gets called when you launch your app. Simply scroll down through the Debug area until you find your font.

(ps.这是我的第一个真正让人头疼的游戏.如果您想查看它,请在AppStore上搜索"Crappy Duck")

(ps. this is from my first really trashy game. If you want to check it out, search "Crappy Duck" on the AppStore)

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

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