react-native-vector-icons 和 自定義字體圖標

安裝和配置react-native-vector-icons

  1. 根目錄下使用npm install react-native-vector-icons --save
  2. 安裝完成後運行react-native link react-native-vector-icons命令link這個庫
  3. Android端的配置:
    打開android /app/src/main中並建立了assets/fonts的目錄 黏貼node_modules/react-native-vector-icons/Fonts的文件

    接着咱們要在android/app/build.gradle文件中添加如下內容:
    dependencies {
        .....
        compile project(':react-native-vector-icons')
        ....
    }

     

阿里矢量圖標庫iconfont的使用

  1. 選擇須要下載的圖標,下載svg格式 前往
  2. 解壓zip文件,能夠看到文件夾中有如下文件 其中demo_unicode.html包含了全部圖標對應的unicode字符,咱們就是用它來顯示圖標。
  3. 將iconfont.ttf文件分別copy到Android和iOS工程目錄下。
    Android放置在app/src/main/assets/fonts文件夾中
  4. 生成iconfont.json 直接使用unicode編碼的方式引用字體圖標不怎麼直觀,畢竟都是unicode編碼,還容易拼寫出錯。這邊咱們須要使用個腳本工具
    iconfont_mapper.sh腳本文件和iconfont.svg放到同一目錄中,打開命令行或終端,執行如下命令:
    ./iconfont_mapper.sh iconfont.svg
    ​​​​​​​
    ​​​​​​​
相關文章
相關標籤/搜索