Reputation: 392
I am trying to use the Nunito-ExtraBoldItalic font for my UILabel.
I followed the steps outlined in tutorials and other answers.
I am using the following code to create a UIlabel:
uiLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 160, height: 50))
let myfont = UIFont(name: "Nunito-ExtraBoldItalic", size: 14)
uiLabel!.font = myfont
uiLabel!.textColor = UIColor(red: CGFloat(51/255.0), green: CGFloat(33/255.0), blue: CGFloat(32/255.0), alpha: CGFloat(100.0))
addSubview(uiLabel!)
But UIFont returns nil.
Postscript name of font is "Nunito-ExtraBoldItalic".
I also tried running the following:
for familyName:String in UIFont.familyNames {
print("Family Name: \(familyName)")
for fontName:String in UIFont.fontNames(forFamilyName: familyName) {
print("--Font Name: \(fontName)")
}
}
My font is not shown.
The font is visible in storyboard and other areas.
I tried using the Nunito-ExtraBoldItalic, Nunito-ExtraBold Italic, Nunito-ExtraBold-Italic as names. None worked.
So I am not sure what the problem is.
Upvotes: 2
Views: 2384
Reputation: 418
Add "Fonts provided by application" in Info.plist.
<key>UIAppFonts</key>
<array>
<string>CarterOne.ttf</string>
</array>
Upvotes: 7
Reputation: 3043
You also need to add the font to the .plist file Please read the following: https://developer.apple.com/documentation/uikit/text_display_and_fonts/adding_a_custom_font_to_your_app
Add the font name to this plist key: "Fonts provided by application"
Upvotes: 1