简体   繁体   English

在Expo中添加自定义图标

[英]Add custom icons in Expo

I am using the native base library and i want to add a custom Icon i made. 我正在使用本机基础库,我想添加一个我制作的自定义图标。 I found some answers like this one , but all answers are for react native and i have to export my files from Expo to edit the android and ios folders. 我发现了一些像这样的答案, 一个 ,但所有的答案都是原生的反应和我有我的文件从世博会导出到编辑的Android和iOS文件夹。

There are three ways to create a custom icon in Expo . 有三种方法可以在Expo创建自定义图标。 I'll tell you one of them. 我告诉你其中之一。 See the rest of the official documents . 请参阅其余的正式文件

Returns your own custom font based on the glyphMap where the key is the icon name and the value is either a UTF-8 character or it's character code. 根据glyphMap返回您自己的自定义字体,其中的键是图标名称,值是UTF-8字符或它的字符代码。 fontFamily is the name of the font NOT the filename . fontFamily是字体的名称,而不是filename The expoAssetId can be anything that you can pass in to Font.loadAsync . expoAssetId可以是您可以传递给Font.loadAsync任何东西。 See react-native-vector-icons for more details. 有关更多详细信息,请参见react-native-vector-icons

Example

import * as React from 'react';
import * as Font from 'expo-font';
import { createIconSet } from '@expo/vector-icons';

const glyphMap = { 'icon-name': 1234, test: '∆' };
const expoAssetId = require("assets/fonts/custom-icon-font.ttf");
const CustomIcon = createIconSet(glyphMap, 'FontName', expoAssetId);

export default class CustomIconExample extends React.Component {  
  render() {
    return (
      <CustomIcon name="icon-name" size={32} color="red" />
    );
  }
}

Useful Links: Documents for the Custom Icon 有用的链接: 自定义图标的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM