I am trying to use Avenir Next on a NSAttributedString w/ UIFontDescriptor. It is an in-built iOS font. It works in my SwiftUI components but if I try to create a custom UIFontDescriptor it doesn't find the font and defaults to SFUI. Why is this and how can I fix it?
// descriptor shows font as SFUI
let boldDescriptor = UIFontDescriptor(fontAttributes: [
UIFontDescriptor.AttributeName.family: "Avenir Next",
UIFontDescriptor.AttributeName.traits: [
UIFontDescriptor.TraitKey.weight: UIFont.Weight.bold
]
])
I'm not sure, How you are using this descriptor method.
Avenir Next is an in-built iOS font, but it may not be available on all devices. Make sure the font is installed on the device you are testing on.
Check font is available by using the
UIFont.fontNames(forFamilyName: "Avenir Next")
method to get a list of available font names for the Avenir Next family.I also created a new project for
boldDescriptor
method & it is working fine in my case.Use this project Demo Project for UIFontDescriptor - GitHub & let me know if this example doesn't work for you.
Output:
Output Screenshot
Also, you can import font from the system into the project.
Please also check the following reasons:
iOS 13
or greater version for testing the fonts. Note on official website