UIFont fontWithName returns nil

前端 未结 6 1251
我寻月下人不归
我寻月下人不归 2020-12-16 10:22

In my info.plist, I added a key \"Fonts provided by application\" and added EdwardianScriptITCStd.otf \"ent

6条回答
  •  渐次进展
    2020-12-16 10:43

    The problem I ran into is that some of the fonts from the font family returned correctly while others returned nil.

    For example:

    • MuseoSansRounded-500 valid
    • MuseoSansRounded-900 nil

    It turned out that Xcode was automatically including custom fonts that had been used in Interface Builder. I had used the 500 weight font in IB but not the 900 weight one.

    These two steps fixed it for me:

    1. In Build Settings, find and disable Auto-Activate Custom Fonts. There were two instances of this in my project.

    2. On app launch, manually register the custom fonts with the system. I used the snippet from this SO answer: https://stackoverflow.com/a/32600784/131378

    In the name of completeness, I could have left Auto-Activate Custom Fonts turned on and then skipped registering those fonts in code. However, I didn't want to update the code during development if I ended up using a new font in IB that was previously being registered manually. Xcode complains if you register a font that was already auto-activated.

提交回复
热议问题