Custom Font in swift

ε祈祈猫儿з 提交于 2019-12-25 00:58:43

问题


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?


回答1:


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

you can see mine here "small_pixel.ttf"

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

you can see that here.

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

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. this is from my first really trashy game. If you want to check it out, search "Crappy Duck" on the AppStore)



来源:https://stackoverflow.com/questions/48564490/custom-font-in-swift

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!