Reputation: 4964
I am trying to use a ttf file for glyph's for an iOS app and having some issue with the font strings... I can read the unicode font's from the ttf file but it doesn't seem the glyph's are getting read from the file.
For example the following code works for a unicode character.
let myFont = UIFont(name: "WeatherIcons-Regular", size: 15)
cell.detailTextLabel?.font = myFont
cell.detailTextLabel?.text = "\u{26c8}"
However if I try to read a glyph, the icon gets displayed as a question mark with a box around it.
let myFont = UIFont(name: "WeatherIcons-Regular", size: 15)
cell.detailTextLabel?.font = myFont
cell.detailTextLabel?.text = "\u{f001}"
Links to the ttf file and css files below.
I have added the font file to my app.
Upvotes: 1
Views: 1364
Reputation: 1134
Make sue you add "Fonts provided by application" (i.e. UIAppFonts) key in the Info.plist of your iOS project, and add item "weathericons-regular-webfont.ttf".
UIAppFonts (Array - iOS) Specifies any app-provided fonts that should be made available through the normal mechanisms. Each item in the array is a string containing the name of a font file (including filename extension) that is located in the app’s bundle. The system loads the specified fonts and makes them available for use by the app when that app is run.
Like this:
Open the font file with Font Book app, we can see the font name is "Weather Icons". Then print all font names to check if the font is available:
print(UIFont.familyNames())
Upvotes: 5
Reputation: 4964
Ensure the ttf
file is included in the target. You can do this by setting the target membership of the font file in the project.
Upvotes: 1