react-native字体react-native-vector-icons在ios下的使用

react-native字体react-native-vector-icons在ios下的使用

官网和网上有各种针对ios/android的安装和使用方法;能够使用了,基本就等于安装成功了。

react-native-vector-icons 的图标分为几个模块, 使用的时候先import FontAwesome from 'react-native-vector-icons/FontAwesome'; 这样才能使用 FontAwesome 标签, 标签内使用 name 字段指定某个图标.

  1. 项目添加依赖:
    yarn add react-native-vector-icons
    
  2. 修改Podfile文件,使用CocoaPods对ios安装这个字体库:
    vim project_dir/ios/Podfile
    pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'
    在ios目录下执行pod install,使用CocoaPods安装这个依赖
    
  3. 修改Info.plist,添加:
    vim project_dir/ios/project_name/Info.plist,添加:
    <key>UIAppFonts</key>
    <array>
      <string>AntDesign.ttf</string>
      <string>Entypo.ttf</string>
      <string>EvilIcons.ttf</string>
      <string>Feather.ttf</string>
      <string>FontAwesome.ttf</string>
      <string>FontAwesome5_Brands.ttf</string>
      <string>FontAwesome5_Regular.ttf</string>
      <string>FontAwesome5_Solid.ttf</string>
      <string>Foundation.ttf</string>
      <string>Ionicons.ttf</string>
      <string>MaterialIcons.ttf</string>
      <string>MaterialCommunityIcons.ttf</string>
      <string>SimpleLineIcons.ttf</string>
      <string>Octicons.ttf</string>
      <string>Zocial.ttf</string>
    </array>
    
  4. 简单使用

    图标名字库

    import Icon from 'react-native-vector-icons/Ionicons';
     
    function ExampleView(props) {
      return <Icon name="ios-person" size={30} color="#4F8EF7" />;
    }
    
    不同的图标使用名字区分;上例的图标名字(Icon-->name)在 [图标名字库](https://oblador.github.io/react-native-vector-icons/)里查找。
    在文件node_modules/react-native-vector-icons/glyphmaps/*.json里也可以看到所有图标的名字
    
  5. android下的使用:据说项目添加依赖后(执行步骤1)执行下面的命令关联下就可以了,待验证
    react-native link react-native-vector-icons
    
  6. react-native-vector-icons自定义图标

  7. 生成svg和字体文件

参考:
  1. https://www.npmjs.com/package/react-native-vector-icons#examples
  2. https://oblador.github.io/react-native-vector-icons/
  3. https://www.jianshu.com/p/2b74ba057287
  4. https://blog.csdn.net/yingBi2014/article/details/102933684
  5. https://www.jianshu.com/p/71e31894877a
posted @ 2019-12-08 12:02  脚本小娃子  阅读(1493)  评论(0编辑  收藏  举报