swiftxcodesprite-kitnsfont

System font not working in iOS Simulator


I've read most all of the questions and answers here on this topic and they all seem to apply to custom fonts, not system fonts.

Im using Interface builder and have a SKLabelNode on a SpriteKit scene that i changed the font to 'Lithos Pro'. It displays correctly in the IB, but does displays a generic font when ran in the Simulator. I also programmatically added a UITextField to the scene trying to use the same font which is not working either.

From what i understand this is included as part of the NSFont bundle, but just to confirm i added the TTF files to the project and included them in my target resources. Still no go.

Thoughts?

nameField = UITextField(frame: CGRect(x: view.center.x - 150,y:view.center.y - 25,width: 300, height: 50))
nameField.font = UIFont(name: "Lithos Pro Regular", size: 25)  //I've tried 'Lithos Pro, LithosPro, and Lithos Pro Regular'
nameField.textAlignment = .center
nameField.borderStyle = UITextBorderStyle.roundedRect
nameField.autocorrectionType = UITextAutocorrectionType.no
nameField.keyboardType = UIKeyboardType.default
nameField.returnKeyType = UIReturnKeyType.done
nameField.clearButtonMode = UITextFieldViewMode.whileEditing;
nameField.contentVerticalAlignment = UIControlContentVerticalAlignment.center
view.addSubview(nameField)

Solution

  • To see all the available system fonts in iOS, go to iosfonts.com. Another way to do this is to print UIFont.familyNames.

    I checked iosfonts.com and there isn't a font called Lithos Pro as of iOS 9. If you can't find the font in the UIFont.familyNames either, that means the font you're using is a custom font, not provided by the OS. Another possibility is that you wrote the whole font name instead of only the family name. Try removing the word Regular.

    If you are using a custom font and have added the font file to the project, you need to add something in Info.plist to make it work. Create a new KVP in the Info.plist file. The key is called "Fonts provided by application" or something similar. Just scroll down the list and you should find it. After that, Xcode will automatically create an array as the value for the key. Then just add your font file name with the extension as the only item in the array.