【问题标题】:Why fontFamily is not working in iOS using React-Native?为什么 fontFamily 不能使用 React-Native 在 iOS 中工作?
【发布时间】:2016-12-03 12:47:10
【问题描述】:

我正在处理 react-native 中的自定义字体,但它在 Android 中运行良好,但在 iOS 中无法运行,错误消息是“无法识别的字体系列”。

iOS 字体系列设置步骤:

  1. 在资源中复制粘贴的 .ttf 文件

  2. Info.plist -> 应用程序提供的字体 -> AllerRegular.ttf

  3. 清理和构建项目。

资源:

Info.plist:

错误信息:

样式表代码:

fonts_label: {
  fontFamily: "AllerRegular",
  fontSize: 12,
}

请仔细阅读帖子并告诉我。

谢谢

【问题讨论】:

  • 尝试删除 ios/build 或 react-native start --reste-cache? + 在构建阶段添加字体以复制捆绑资源。
  • @Deeptiman Pattnaik 你对这个问题有什么想法吗?

标签: react-native font-family


【解决方案1】:

100% 适用于 Android 和 iOS 中的自定义字体家族的解决方案

1) Add the "font.ttf" file to Assets folder in React Native App.
2) Open "font.ttf" file in Font Book (in macbook).
3) Find the PostScript name "fontName" (you will get this text at the top).
4) Rename the "font.ttf" with PostScript name "fontName" ("fontName.ttf").

5) Added this code to Package.json
"rnpm": {
        "assets": [
      "./assets/fonts/"
        ]
    }
6)Then run the below code to link assets:

反应原生链接

7) Close everything and start again and run the react native app.

【讨论】:

    【解决方案2】:

    iOS 不像 Android 那样使用文件名来识别字体。您可以使用 OS X Font Book App 打开字体文件并自行检查,或者您可以让您的应用告诉您它将使用的确切名称,详见this post (Step 5: Find the name of the font)。我怀疑你的问题出在哪里。否则,请检查您是否遵循了该文章中详述的所有步骤。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-06
      • 1970-01-01
      相关资源
      最近更新 更多