SwiftUI won't display custom font

后端 未结 3 1702
猫巷女王i
猫巷女王i 2020-12-11 07:58

I\'m currently trying to add a custom font to my project, but I somehow won\'t work.

I\'ve already added the .otf file to a font folder, checked that it targets to

3条回答
  •  一整个雨季
    2020-12-11 08:02

    I had the exact same problem. The following steps fixed it for me. I'm currently using Xcode 11.4.1

    1. Create a storyboard, add a label and select your font in the inspector as font for the label.
    2. Build your App in the Simulator
    3. Check the installed fonts with:

      for family in UIFont.familyNames.sorted() {
          let names = UIFont.fontNames(forFamilyName: family)
          print("Family: \(family) Font names: \(names)")
      }
      
    4. If it's appearing you can use it also programmatically

    Here is also a list of Common mistakes with adding custom fonts

提交回复
热议问题