Unrecognized font family on iOS simulator with Rea

2020-05-25 07:10发布

I've added Linux Biolinum fonts (http://www.dafont.com/linux-biolinum.font, LinBiolinum_R.ttf, LinBiolinum_RB.ttf) to my React Native project. Android version is OK. But on iOS I always see error "Unrecognized font family LinBiolinum_R".

enter image description here

My style is:

customFontRegular: {
    fontFamily: 'LinBiolinum_R',
},

I've tryied to rename font file and font family to "MyFont", but the error appears again on iOS.

Any ideas?

10条回答
劳资没心,怎么记你
2楼-- · 2020-05-25 07:32

Implement the following code in your appdelegate file

for (NSString* family in [UIFont familyNames])
{
    NSLog(@"%@", family);

    for (NSString* name in [UIFont fontNamesForFamilyName: family])
    {
        NSLog(@"Family name:  %@", name);
    }
}

You should use FONT FAMILY NAME instead of your font file name like the following

fontFamily: "FuturaBT-Book"
查看更多
Melony?
3楼-- · 2020-05-25 07:34

On Android it takes the name of the file and you are done. On iOS however it is a bit more complex.

There are a few steps you should take:

  • Double check the font files are included in the Target in XCode
  • Make sure they are included in the step "Copy Bundle Resources" (add files, not folders)
  • Include them in the Info.plist of the app
  • Find the name of the Font through FontBook or with some log statements in your AppDelegate

Explained in more detail here: http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/

Good luck!

查看更多
Emotional °昔
4楼-- · 2020-05-25 07:39

For me, changing the name of the file to the name of the Font (displayed as I open the file) did it.

查看更多
Anthone
5楼-- · 2020-05-25 07:39

If you are running react-native ios simulator, you should include fonts in the xcode project directory.

react-native link react-native-vector-icons doing so , will add the fonts to Resources folder in xcode project and also add fonts to pinfo list.

查看更多
相关推荐>>
6楼-- · 2020-05-25 07:41

Add this to your package.json

"rnpm":{
    "assets":[
        "./assests/fonts/"
    ]
}

and then run react-native link in command line

查看更多
Anthone
7楼-- · 2020-05-25 07:41

For IOS,

  • Make sure you add fonts to resource Copy Bundle Resources

  • Make sure you have folder Resources in Xcode, somehow it was deleted and you must create, import fonts to that folder manually

  • Make sure using name of Family in Font book

查看更多
登录 后发表回答