【问题标题】:Add custom font family in React Native iOS在 React Native iOS 中添加自定义字体系列
【发布时间】:2017-12-28 15:46:35
【问题描述】:

我想在 iOS 上的 React Native App 上添加自定义字体系列。我对 Android 没有问题,但我在 iOS 中有一个错误:

无法识别的字体系列“dinproRegular”

我使用this link 设置我的字体,但没有结果。

文件名:dinproRegular.ttf

调用 react-native : fontFamily: "dinproRegular" // Test with "Dinpro Regular" too

没有结果:(

有人知道吗?

【问题讨论】:

    标签: ios xcode reactjs react-native


    【解决方案1】:

    只需检查当前安装在 Ios 或 Android 中的字体:

    https://github.com/react-native-training/react-native-fonts

    如果要添加自定义字体:

    https://medium.com/@danielskripnik/how-to-add-and-remove-custom-fonts-in-react-native-b2830084b0e4

    希望对你有帮助!

    【讨论】:

    • 我尝试过使用 Google 字体,它可以工作。你认为这是因为 DinPro 不是免费的吗?也许文件是问题?
    • 如果文件正确,我认为这不会是错误。您是否在 package.json 中正确链接了字体路径?
    • 是的 :) 我的路径是正确的,我尝试使用其他字体并且它可以工作
    • 好吧,所以确定这是这种字体类型的问题。可能你没有下载好或者确定 ios 完全兼容那个字体。
    【解决方案2】:

    在 iOS 中,您可以查看应在代码中使用的字体名称以使其正常工作 在 AppDelegate.m 中使用以下代码来获取您的应用支持的所有字体名称。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-30
      • 1970-01-01
      • 1970-01-01
      • 2019-01-21
      • 1970-01-01
      相关资源
      最近更新 更多