Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding multiple fonts to UIAppFonts overrides each other

Tags:

iphone

uifont

I'm trying to add some custom fonts to an iPhone app through UIAppFonts in Info.plist.

I can reach both fontnames by code, i.e. MyFont-Bold and MyFont-Medium.

My problem is that the last font in UIAppFonts array overrides the other one, making both MyFont-Bold and MyFont-Medium render out MyFont-Bold if this is the last entry in the plist array. By dragging MyFont-Bold as the first entry makes both font-names render MyFont-Medium.

The property list excerpt:

UIAppFonts
  item 0    MyFont-Medium
  item 1    MyFont-Bold

I'm calling the font with:

UIFont* applicationFontBold = [UIFont fontWithName:@"MyFont-Bold"
                                              size:[UIFont buttonFontSize]];

UIFont* applicationFont = [UIFont fontWithName:@"MyFont-Medium"
                                          size:[UIFont buttonFontSize]];

Anyone tried adding multiple fonts to one font-family?

like image 640
doh Avatar asked Nov 22 '10 13:11

doh


People also ask

How do I add fonts to info plist?

To do this, add the key "Fonts provided by application" to Info. plist (the raw key name is UIAppFonts ). Xcode creates an array value for the key; add the name of the font file as an item of the array. Be sure to include the file extension as part of the name.

How do I add fonts to Swift 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.


1 Answers

Don't know if it was ever fixed, but I worked around this issue by actually modifying the font family names inside the .ttf files, using vim editor. Because you have different font-types (Bold and Medium) but actually the same fontfamily (MyFont) - the system mixes them up. So what I did in the first file - I actually modified the family to be MyFontA, and in the second file MyFontB (of course I had different names - these are just to match the example above). This worked perfect.

like image 113
justadreamer Avatar answered Sep 25 '22 01:09

justadreamer