(35)-react-native-icons插件

最后更新于:2022-04-01 06:51:05

> [react-native-icons](https://github.com/corymsmith/react-native-icons) ## 下载 在项目的根目录下执行`npm install react-native-icons@latest --save`,下载完成后可以在node_modules目录下看到该插件: ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-01-07_568e13f49b570.jpg) ## 配置 目前只支持iOS,所以只有xcode的配置: ## 导入ReactNativeIcons.xcodeproj 1.项目`Libraries`上右键: ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-01-07_568e13f4c4750.jpg) 添加项目根目录下的`node_modules/react-native-icons/ios/ReactNativeIcons.xcodeproj`  2.引用libReactNativeIcons.a:  单机项目,在右面的面板中选择`Build Phases`下的`Link Binary With Libraries`,点击`+`号添加库:  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-01-07_568e13f502646.jpg)  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-01-07_568e13f52514c.jpg) 3.添加ttf文件:  这个地方要注意,github上直说了引用`node_modules/react-native-icons/ios/ReactNativeIcons/Libraries/FontAwesomeKit`文件夹,但是主要的还是4个ttf文件: 单机项目,在右面的面板中选择`Build Phases`下`Copy Bundle Resources`选择`+`号,在出现的文件选择器中点击`Add Other...`,定位到`node_modules/react-native-icons/ios/ReactNativeIcons/Libraries/FontAwesomeKit`目录下,把所有的ttf文件和otf都勾选上: ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-01-07_568e13f547d1f.jpg)  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-01-07_568e13f568068.jpg)  ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-01-07_568e13f5807df.jpg) ## Import 要想使用`react-native-icons`,需要在代码中添加如下语句: ~~~ var { Icon, } = require('react-native-icons'); ~~~ ## 选择图标 | 类别 | 图标数量 | 引用名 | | --- | --- | --- | | [FontAwesome 4.4](http://fortawesome.github.io/Font-Awesome/icons/) | 585 | fontawesome | | [ionicons 2.0.0](http://ionicons.com/) | 733 | ion | | [Foundation icons](http://zurb.com/playground/foundation-icon-fonts-3) | 283 | foundation | | [Zocial](http://zocial.smcllns.com/) | 99 | zocial | | [Material design icons](http://google.github.io/material-design-icons/) | 744 | material | ## 实例 我们在FontAwesome4.4网站上找了一个apple图标: ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-01-07_568e13f5a4a76.jpg) 怎么用呢?看下面代码: ~~~ 'use strict'; var React = require('react-native'); var { Icon, } = require('react-native-icons'); var { AppRegistry, StyleSheet, View, } = React; var TesterHome = React.createClass({ render() { return ( < Icon name = 'fontawesome|apple' size = { 150 } style = { styles.beer } /> ); } }); var styles = StyleSheet.create({ container: { flex: 1, }, beer: { width: 150, height: 150, } }); AppRegistry.registerComponent('TesterHome', () => TesterHome); ~~~ 核心代码是`fontawesome|apple`就是这么简单.所以的引用都是`库名的引用名|图标的名称`,效果如下: ![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-01-07_568e13f5c32bd.jpg)
';