简体   繁体   English

反应原生图标

[英]React native icons

Somebody try to use react-native-icons?有人尝试使用 react-native-icons 吗? I follow this steps:我按照以下步骤操作:

  • npm install react-native-icons@latest --save npm install react-native-icons@latest --save
  • In XCode, in the project navigator right click Libraries ➜ Add Files to [your project's name]在 XCode 中,在项目导航器中右键单击 Libraries ➜ Add Files to [your project's name]
  • Go to node_modules ➜ react-native-icons➜ ios and add ReactNativeIcons.xcodeproj转到 node_modules ➜ react-native-icons➜ ios 并添加 ReactNativeIcons.xcodeproj
  • Add libReactNativeIcons.a (from 'Products' under ReactNativeIcons.xcodeproj) to your project's Build Phases ➜ Link Binary With Libraries phase将 libReactNativeIcons.a(来自 ReactNativeIcons.xcodeproj 下的“产品”)添加到您项目的构建阶段 ➜ Link Binary With Libraries 阶段
  • Add the font files you want to use into the Copy Bundle Resources build phase of your project (click the '+' and click 'Add Other...' then choose the font files from node_modules/react-native-icons/ios/Libraries/FontAwesomeKit).将要使用的字体文件添加到项目的 Copy Bundle Resources 构建阶段(单击“+”并单击“添加其他...”,然后从 node_modules/react-native-icons/ios/Libraries 中选择字体文件/FontAwesomeKit)。 Run your project (Cmd+R)运行你的项目 (Cmd+R)

My Code我的代码

var React = require('react-native');
var Icon = require('FAKIconImage');
var { AppRegistry, StyleSheet, Text, View} = React;

class BringgersApp extends React.Component {

  constructor(props) {
    super(props);
  }

  render() {
    return(
      <View style={styles.container}>        
        <Text style={styles.welcome}>
          Welcome to Bringgers!          
        </Text>
        <Icon
          name='ion|beer'
          size={150}
          color='#887700'
          style={styles.beer} />       
      </View>
    )
  }
}

var styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

React.AppRegistry.registerComponent('BringgersApp', function() { return BringgersApp });

After I build, he says the file doesn't exist...我构建后,他说该文件不存在...

Font file doesn't exist

I clean the DerivedData and try to build many times, but doesn't work.我清理了 DerivedData 并尝试多次构建,但不起作用。

Steps to install and usage Ionicons , FontAwesome and Entypo font Icons in react-native . 反应原生中安装和使用IoniconsFontAwesomeEntypo字体图标的步骤。

First you need to install using following command. 首先,您需要使用以下命令进行安装。

react-native install react-native-vector-icons

Then Required to Link: 然后需要链接:

react-native link react-native-vector-icons

Import font package files to your page: 将字体包文件导入页面:

import Ionicons from 'react-native-vector-icons/Ionicons';
import FontAwesome from 'react-native-vector-icons/FontAwesome';
import Entypo from 'react-native-vector-icons/Entypo';

Usage Example: 用法示例:

<View>
    <Text>Ionicons Icons</Text>
    <Icon name='md-bicycle' />

    <Text>FontAwesome Icons</Text>
    <FontAwesome name='trophy' />

    <Text>Entypo Icons</Text>
    <Entypo name='aircraft' />
</View>

If you want to see list of available icons, you can look in this directory: 如果要查看可用图标列表,可以查看以下目录:

Ionicons: Ionicons:

\node_modules\react-native-vector-icons\glyphmaps\Ionicons.json

FontAwesome: FontAwesome:

\node_modules\react-native-vector-icons\glyphmaps\FontAwesome.json

Entypo: Entypo:

\node_modules\react-native-vector-icons\glyphmaps\Entypo.json 

Giving you my apps screenshot. 给你我的应用截图。

在此输入图像描述

First things first, 首先,

  • the maintainer of react-native-icons himself points to the newer & maintained react-native-vector-icons react-native-icons的维护者自己指向更新且维护的react-native-vector-icons
  • Apparently as of now the rnpm project has been merged into react-native. 显然截至目前, rnpm项目已合并为react-native。

In other words, your life can be as easy as typing 换句话说,你的生活就像打字一样简单

react-native install react-native-vector-icons
react-native link react-native-vector-icons

And you may be good to go*) 你可能会很高兴*)

*) at least it worked on my machine *) 至少它在我的机器上工作

您是否将文件node_modules/react-native-icons/ios/ReactNativeIcons/Libraries/FontAwesomeKit/ionicons.ttf到您的项目中?

  1. Do you have "Build settings" -> "Header Search Paths" -> "$(SRCROOT)/node_modules/react-native/React" recursive? 你有“构建设置” - >“标题搜索路径” - >“$(SRCROOT)/ node_modules / react-native / React”递归吗?
  2. Did you include icon fonts to "Build phases" -> "Copy Bundle Resources" in your Main project? 您是否在主项目中将图标字体包含在“构建阶段” - >“复制捆绑资源”中?

So in my project, I access the Icons through this code: let { Icon, } = require('react-native-icons'); 所以在我的项目中,我通过以下代码访问图标: let { Icon, } = require('react-native-icons');

Although I never had issues using FontAwesome icons, I had issues using Material Icons. 虽然我从未遇到使用FontAwesome图标的问题,但我在使用Material Icons时遇到了问题。 You can also check out react-native-vector-icons . 您还可以查看react-native-vector-icons

Use React Native Package Manager : https://github.com/rnpm/rnpm 使用React Native Package Manager: https//github.com/rnpm/rnpm

$ npm install rnpm -g Running $ npm install rnpm -g正在运行

Installing dependency: 安装依赖:

If you want to install a dependency and link it in one run: 如果要安装依赖项并在一次运行中链接它:

$ rnpm install react-native-icons Linking dependency: $ rnpm install react-native-icons链接依赖:

If you already have some installed (but not linked) modules, run: 如果您已经安装了一些(但未链接)模块,请运行:

$ rnpm link $ rnpm链接

try 尝试

rnpm link // If you installed module

Also

npm install module-name

and after execute 并在执行之后

rnpm link

restart services.. 重启服务..

This code relink automatic your modules. 此代码重新链接自动模块。

Work to me. 对我有用 Thanks. 谢谢。

you can also try with native-base library. 您也可以尝试使用本机库。 it provide tag it is easy and simple to use any icon which can be use with mobile devices. 它提供标签,使用任何可用于移动设备的图标都很容易和简单。

follow this link for more information on native base icon. 有关本机基本图标的更多信息,请点击此链接。 http://nativebase.io/docs/v2.0.0/components#icon http://nativebase.io/docs/v2.0.0/components#icon

follow this link for more information on list of icon. 有关图标列表的更多信息,请点击此链接。 https://ionicframework.com/docs/v2/ionicons/ https://ionicframework.com/docs/v2/ionicons/

ex. 恩。

<Icon name='ios-list'  style={style.icon} />

Step 1: Install react-native-elements 第1步:安装react-native-elements

yarn add react-native-elements
# or with npm
npm i react-native-elements --save

Step 2: Install react-native-vector-icons 第2步:安装react-native-vector-icons

If you have already installed react-native-vector-icons as a dependency for your project you can skip this step. 如果您已经安装了react-native-vector-icons作为项目的依赖项,则可以跳过此步骤。 Otherwise run the following command: 否则运行以下命令:

# yarn
yarn add react-native-vector-icons
# or with npm
npm i --save react-native-vector-icons

# link
react-native link react-native-vector-icons

and after this just simply use them in your project like 之后只需在你的项目中使用它们就好了

import { Icon } from 'react-native-elements';

class IonBeer extends React.Component {
  render() {
    return (
         <Icon
          name='md-beer'
          type='ionicon'
          color='#887700'
          size=150
        />
    );
  }
}

and then simply use it like. 然后简单地使用它。

<IonBeer/>

any where you want 任何你想的地点都可以

For using icons in react native, there are many libraries available, react-native-vector-icons is one of them, it is very easy to use.对于在 react native 中使用图标,有很多可用的库, react-native-vector-icons就是其中之一,非常好用。

just follow 2 steps, first you have to install library, then you have to link it also, to use it in your project.只需遵循 2 个步骤,首先您必须安装库,然后您还必须链接它,以便在您的项目中使用它。

Run this command for installing library运行此命令以安装库

  • npm install react-native-vector-icons --save

Run this command for linking library运行此命令以链接库

  • react-native link react-native-vector-icons

How to use this library如何使用这个库

You can use any directory showed in the image, each directory has a lots of icons in it, now you have to choose which directory has a best icon for you...您可以使用图像中显示的任何目录,每个目录中有很多图标,现在您必须选择哪个目录具有最适合您的图标...

For finding best directory for you, I will recommend you, simply visit this link:为了找到最适合您的目录,我会向您推荐,只需访问此链接:

Find best icon for your app为您的应用找到最佳图标

On this website simply search the name of icon you are lookig for, You will get matching icons in all directories, you can simply remember the name of your selected icon, and use it in your app...在本网站上搜索您要查找的图标名称,您将在所有目录中获得匹配的图标,您只需记住所选图标的名称,并在您的应用程序中使用它...

suppose I search arrow on this link, and I selected arrowsalt from AntDesign directory and want to use it in my App.假设我在链接上搜索箭头,并且我从 AntDesign 目录中选择了arrowsalt并希望在我的应用程序中使用它。

import Icon from 'react-native-vector-icons/AntDesign';

if you want to use FontAwesome, then simply replace AntDesign with FontAwesome , or the name of directory you want to use.如果您想使用 FontAwesome,那么只需将AntDesign替换为FontAwesome或您要使用的目录名称。 eg import Icon from 'react-native-vector-icons/DirectoryName';例如从'react-native-vector-icons/DirectoryName'导入图标;

And use icon like this.并使用这样的图标。

<Icon name="arrowsalt" size={30} color="blue" />

For further details Visit this link有关更多详细信息,请访问此链接

Reference:参考:

For Icon you can use react-native vector icon . 对于Icon,您可以使用react-native矢量图标。 It comprises of various icon that we can use in your project for a native look . 它包含各种图标,我们可以在您的项目中使用它以获得原生外观。

for more you can have a look https://github.com/oblador/react-native-vector-icons . 您可以查看更多内容https://github.com/oblador/react-native-vector-icons

For more native components you can have a look at nativebase.io .It's an awesome library for UI in react native . 对于更多的本机组件,您可以查看nativebase.io。它是一个非常棒的UI本地反应UI。

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

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