I’m unable to get any custom fonts working based on the instructions in Apple’s docs and stack overflow answers. Here is my setup that I would expect to work:
1) When copying font files into project:
2) Font .ttf files are added to project
3) Target membership is selected
4) Font names added to UIAppFonts in info.plist
<key>UIAppFonts</key>
<array>
<String>SourceSerifPro-Black.ttf</String>
<String>SourceSerifPro-BlackItalic.ttf</String>
<String>SourceSerifPro-Bold.ttf</String>
<String>SourceSerifPro-BoldItalic.ttf</String>
<String>SourceSerifPro-ExtraLight.ttf</String>
<String>SourceSerifPro-ExtraLightItalic.ttf</String>
<String>SourceSerifPro-Italic.ttf</String>
<String>SourceSerifPro-Light.ttf</String>
<String>SourceSerifPro-LightItalic.ttf</String>
<String>SourceSerifPro-Regular.ttf</String>
<String>SourceSerifPro-SemiBold.ttf</String>
<String>SourceSerifPro-SemiBoldItalic.ttf</String>
</array>
5) Fonts are present under Copy Bundle Resources
6) All system fonts are logged, but new fonts are not found
for family in UIFont.familyNames.sorted() {
let names = UIFont.fontNames(forFamilyName: family)
print("Family: (family) Font names: (names)")
}
7) Tried using the font but only seeing the default font
Text("Test text")
.font(.custom("SourceSerifPro-Regular", size: 20))
I’ve also erased and restarted the simulator and restart my computer and Xcode multiple times. Any idea what else I may be missing?
2
Answers
I had ran into similar problem. Try calling this function once before using any custom font.
Adding custom font to Xcode 13+
Do take note. I made the mistake not adding the extension.ttf so it didn’t import. But otherwise it should.