fontFamily“Courier”不是系统字体 native-base expo

Cam*_*ega 5 ios react-native native-base expo

我正在使用 expo 的本机基本模板expo-template-native-base,启动 iOS 模拟器时出现错误

fontFamily "Courier" is not a system font and has not been loaded through Font.loadAsync.

- If you intended to use a system font, make sure you typed the name correctly and that it is supported by your device operating system.

- If this is a custom font, be sure to load it with Font.loadAsync.
at node_modules/expo-font/build/Font.js:27:16 in processFontFamily
at node_modules/react-native/Libraries/ReactNative/renderApplication.js:54:4 in renderApplication
at node_modules/react-native/Libraries/ReactNative/AppRegistry.js:117:25 in runnables.appKey.run
at node_modules/react-native/Libraries/ReactNative/AppRegistry.js:213:4 in runApplication
Run Code Online (Sandbox Code Playgroud)

有想法该怎么解决这个吗?

Rok*_*kas 0

此警告表明您尝试在 Expo 项目中使用的 Courier 字体在设备上不可用,并且您尚未使用expo-font. 如果您遇到此问题,可以通过以下方式修复:

  1. 安装expo-fontnpx expo install expo-font
  2. 下载字体:您可以从 Google Fonts 下载 Courier 字体。我是从fonts-free下载的。
  3. 将字体添加到您的 Expo 项目中,并创建一个字体文件夹。通常位于项目根目录或资产文件夹中。
  4. 导入并加载字体:
import * as Font from 'expo-font';
import { useEffect } from "react";

const loadFonts = async () => {
  await Font.loadAsync({
   Courier: require('./fonts/Courier.ttf'), // Replace with path
  });
};

useEffect(() => {
  loadFonts();
}, []);
Run Code Online (Sandbox Code Playgroud)
  1. 在样式中使用该字体,加载字体后,您可以使用其名称(“Courier”)引用它