我正在尝试在本机反应中使用自定义字体。使用 Icomoon 在自定义图标集中转换了 SVG,并尝试了https://www.reactnative.guide/12-svg-icons-using-react-native-vector-icons/12.1-creating-custom-iconset.html中的所有步骤。
react-native-vector-icons
已经安装了。
用于react-native link react-native-vector-icons
设置项目的矢量图标框架。
将 selection.json 和 Icomoon.ttf 文件放在assets/fonts
文件夹中。
并添加 "rnpm": { "assets": [ "resources/fonts" ] }
到 package.json 文件中
创建 CustomIcon.js 文件并添加
import {createIconSetFromIcoMoon} from 'react-native-vector-icons';
import icoMoonConfig from './selection.json';
export default createIconSetFromIcoMoon(icoMoonConfig);
在 App.js 文件中添加了以下内容
import CustomIcon from './components/CustomIcon.js'
<CustomIcon name='accounts' size={50} /> //To use the icon
并且图标在图标位置显示☒。
如果有人有解决方案请分享,谢谢。