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?
- Create a new folder in your project directory and move your custom fonts there.
- In the left sidebar, select your target, then create the stage and you should see the copy bundle resource .
- Make sure your fonts are included in the list. If they are not, then include them by clicking the + button.
Comments
Post a Comment