Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load font in iOS 11 (or Xcode 9)

Tags:

ios

swift

fonts

I have been using Futura-Demi.otf font for a while.

With the below code, I could confirm this file contains multiple fonts.

for fname in UIFont.familyNames {
    for name in UIFont.fontNames(forFamilyName: fname) {
        print(name)
    }
}

Font family is Futura and it contains fonts as below:

Futura-CondensedExtraBold
Futura-Dem
Futura-Medium
Futura-Bold
Futura-CondensedMedium
Futura-MediumItalic

I have used Futura-Dem font with UIFont(name: "Futura-Dem", size: 21) without any trouble so far. However after iOS 11 is released, I can't use this font anymore. All Futura-Dem font are changed to Futura-Medium even in the app which already in App Store.

I checked that the font loaded by UIFont(name: "Futura-Dem", size: 21) is Futura-Medium font and I also found that I can use Futura-Dem font with

let des = UIFontDescriptor(name: "Futura-Dem", size: 21)
let font = UIFont(descriptor: des, size: 21)

The above code loads Futura-Dem successfully but I have no idea why I can't just use UIFont(name: "Futura-Dem", size: 21) as I did before.

like image 405
Ryan Avatar asked Sep 20 '17 18:09

Ryan


People also ask

How do I import a font into Xcode?

To add a font file to your Xcode project, select File > Add Files to “Your Project Name” from the menu bar, or drag the file from Finder and drop it into your Xcode project. You can add True Type Font (. ttf) and Open Type Font (. otf) files.

How do I add fonts to Xcode 13?

Add the font file to your Xcode project Select File menu > Add Files to "Your Project Name"... from the menu bar, select all the fonts you need to add, then click the Add button. Or drag the file from Finder and drop it into your Xcode project. Drag the font files from Finder and drop it into your Xcode project.

What is the font used in Xcode?

SF Mono. This monospaced variant of San Francisco enables alignment between rows and columns of text, and is used in coding environments like Xcode.


1 Answers

I've had the same issue, with a custom Futura font as well.

I used the software Birdfont ( https://birdfont.org/ *) to rename the font to something different (not starting with Futura, just a single word starting with an upper case). And changing the filename as well but really what was important was to change the font name in the font's meta data.

Then I linked that renamed font to the iOS app and it worked. I don't know why the problem with Futura occurred though, but this trick solved the problem.

*Note: there is also FontForge ( http://fontforge.github.io/en-US/ ) if for some reasons Birdfont doesn't work for you.

like image 189
Testounet Testounet Avatar answered Oct 25 '22 18:10

Testounet Testounet