Custom Font not working in Swift/Xcode -


I have a problem in custom fonts in my project. I tried both ways: By Code and Interface Builder

I added TeamSpiritNF.ttf to the project and added it to info.plist (the font provided by the application).

Then in the code I have entered this:

  self.navigationController? .navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont (name: "TeamSpiritNF", size: 30)! ]  

The app crashes when entering the screen in the simulator:

  Fatal Error: Opening an optional value returns unexpectedly to zero  

But if I change the font name to Helvetica for example, then only one row works fine.

And if I use this font for a label in the interface builder (where I can select it from the dropdown), it is shown correctly in the preview. But when I enter that screen in the simulator, that screen is delayed and the label uses Helvetica New instead of TeamSpiritNF.

Does anyone know what the problem can be?

  1. Create a new folder in your project directory and move your custom fonts there.
  2. In the left sidebar, select your target, then create the stage and you should see the copy bundle resource .
  3. Make sure your fonts are included in the list. If they are not, then include them by clicking the + button.

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -