一. 切換到工程目錄,執(zhí)行
- 執(zhí)行安裝命令
npm install react-native-vector-icons --save
或者
yarn add react-native-vector-icons
注意:目前npm5存在安裝新庫時會刪除其他庫的問題,可能后面會修復(fù)導(dǎo)致項目無法正常運行。請盡量使用yarn代替npm操作。
- 執(zhí)行以下命令鏈接原生庫
react-native link react-native-vector-icons
二. ios配置(ios需要單獨導(dǎo)入字體文件,安卓link完就可以用了)
-
右鍵工程文件Add Files to "(你工程名)"
image.png 選擇node_modules/react-native-vector-icons/Fonts文件夾

image.png
三. 使用
- 如果用的是ionicons,打開這個地址點擊相應(yīng)的圖標復(fù)制名字http://ionicframework.com/docs/ionicons/
image.png
2.創(chuàng)建一個demo頁面,以下是使用demo
import React from 'react';
import Icon from 'react-native-vector-icons/Ionicons';
const Icon = () => {
return <Icon name="ios-add" size={30} color="red" />
};
完美收官!
項目demo地址:https://github.com/duheng/Mozi
THE END!

