Overriding the default font in Swift

Want to change all of the default fonts in your App, in one fell swoop?

Image for post
Image for post

Prerequisites:

  • Be able to use Xcode (certainly to create an App!)

Terminology

TTF: TrueType Fonts, that were originally developed by Apple

OFT: OpenType Fonts, a relatively newer font that has been based on the TrueType standard

The implementation

You will need to have added a custom font into your project, and of course have linked to this through your .plist file. Done? No problem.

I set up a Resources.swift file with the following contents:

And then this can be called from AppDelegate (for example didFinishLaunchingWithOptions)

Conclusion

You can get a prototype App looking production ready faster than ever before using this technique. So why not get to it?

Questions?

Any queries? Get in touch using this Twitter channel:

I’d love to hear from you. Claps? If you like…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store