首页 文章

React-Native无法解析字体模块

提问于
浏览
1

我正在开始一个非常基本的构建 . 我正在使用`create-react-native-app'和yarn for pm .

从那里我试图完成的是为一些UI元素加载'native-base' .

从app.js文件中我唯一添加的是来自native-base的Button Component .

<Button> <Text></Text> </Button>

并包括原生基地 .

收到一些错误后,我去了@poo / vector-icons,并为它的地狱运行 react-native link .

现在它可以找到@ expo / vector-icons但它找不到以 Ionicons.ttf 开头的字体 .

所以 . 从那里我将所有字体下载到 assets/fonts/ 目录,然后根据我在展会网站上找到的一些文档将其包含在我的 app.js 文件中 .

import { Font } from 'exponent';
///
export default class App extends React.Component {
  componentDidMount() {
    Font.loadAsync({
      'ionicons': require('./assets/fonts/Ionicons.ttf'),
    });
  }
///

1 回答

  • 0

    他们加载自定义字体的方式是将它们添加到Info.plist文件中,作为应用程序提供的Font列表:

    enter image description here

    他们还需要在构建阶段提供的资源中:

    enter image description here

    之后,您可以在CSS in native native中的fontFamily属性中使用它 . 确保在添加字体后再次清理并构建项目,以便将它们复制到设备中 .

相关问题