react native cli 使用react-native-vector-icons图标库
1. 安装
npm install --save react-native-vector-icons
2. 修改配置
安卓且使用 Gradle:修改
android/app/build.gradle
文件,
添加apply from: file("../../node_modules/react-native-vector-icons/fonts.gradle")
。
3. 使用图标
import Icon from 'react-native-vector-icons/Ionicons';
function ExampleView(props) {
return <Icon name="ios-person" size={30} color="#4F8EF7" />;
}
图标库的图标来自不同渠道,使用时引入对应的模块即可:
如:
Ionicons
下的图标,就引入import Ionicons from 'react-native-vector-icons/Ionicons';
使用:<Ionicons name="ios-person" size={30} color="#4F8EF7" />
AntDesign
下的图标,就引入import AntDesign from 'react-native-vector-icons/AntDesign';
使用:<AntDesign name="ios-person" size={30} color="#4F8EF7" />
图标集合列举: