npm install react-native-vector-icons --save (回車)
複製代碼
react-native link react-native-vector-icons
複製代碼
import Ionicons from 'react-native-vector-icons/Ionicons'
const AppBottomNavigator = createBottomTabNavigator({
Home:{
screen:Home,
navigationOptions:{
tabBarLabel:'首頁',
tabBarIcon:({tintColor,focused})=>{
return(
<Ionicons
name='icon-home'
size={26}
style={{color:tintColor}}
/>
)
},
/* tabBarOptions: {//可單獨配置顏色
activeTintColor: 'tomato',
inactiveTintColor: 'gray',
},*/
}
},
})
複製代碼
"scripts": {
"build:iconfont": "iconfonttojson ./font/iconfont.css"
},
//若是iconfonttojson運行報錯那麼須要全局安裝
npm install iconfont-to-json -g
複製代碼
npm run build:iconfont
font目錄下會生成一個iconfont.js文件爲了不分不清圖標最好在iconfont字體倉庫裏面編輯一下
Font Class / Symbol
後才下載css
export default {
"icon-31daishouhuo": 58883,
"icon-31daipingjia": 58884,
"icon-31faner": 58885,
"icon-shopcar_active": 58886,
"icon-shopcar": 58887,
"icon-home_active": 58888,
"icon-home": 58889
}
複製代碼
import { createIconSet } from 'react-native-vector-icons'
import fontMap from './iconfont'
export const Iconfont = createIconSet(fontMap,'Iconfont','iconfont.ttf')
複製代碼
import { Iconfont } from "../font";
<Iconfont
name='icon-home'
size={26}
style={{color:tintColor}}
/>
複製代碼