小程式tabBar用法執行個體詳解,小程式tabbar
本文執行個體講述了小程式tabBar用法。分享給大家供大家參考,具體如下:
1、效果展示
2、原理:在app.json中配置tabBar屬性
{ "pages": [ "index", "picDisplay" ], "window": { "navigationBarBackgroundColor": "#ffffff", "navigationBarTextStyle": "black", "navigationBarTitleText": "首頁", "backgroundColor": "#eeeeee", "backgroundTextStyle": "light", "enablePullDownRefresh": false }, "tabBar": { "color":"#666666", "selectedColor":"#06bd04", "list": [{ "pagePath": "index", "text": "首頁", "iconPath": "images/index.png", "selectedIconPath": "images/indexHL.png" },{ "pagePath": "picDisplay", "text": "圖片展示", "iconPath": "images/picDisplay.png", "selectedIconPath": "images/picDisplayHL.png" }] }}
3、關鍵代碼
"tabBar": { "color":"#666666", "selectedColor":"#06bd04", "list": [{ "pagePath": "index", "text": "首頁", "iconPath": "images/index.png", "selectedIconPath": "images/indexHL.png" },{ "pagePath": "picDisplay", "text": "圖片展示", "iconPath": "images/picDisplay.png", "selectedIconPath": "images/picDisplayHL.png" }] }
4、操作方法
建立一個項目,開啟app.json檔案,將關鍵代碼複製到"window":{},後面,注意window的大括弧前加逗號,如
配置tabBar屬性值
"tabBar": { //設定tabBar文字預設顏色 "color":"#666666", //設定tabBar文字被選中是的顏色 "selectedColor":"#06bd04", //tab列表,數群組類型,改數組內至少要有兩個但不大於5個的tab對象 "list": [{ //設定tab跳轉頁面連結 "pagePath": "index", //設定tab上的文字 "text": "首頁", //設定tab上的預設表徵圖 "iconPath": "images/index.png", //設定tab被選中時的表徵圖 "selectedIconPath": "images/indexHL.png" },{ "pagePath": "picDisplay", "text": "圖片展示", "iconPath": "images/picDisplay.png", "selectedIconPath": "images/picDisplayHL.png" }] }
tabBar的5種常用屬性與配置說明:
1) color:未選擇字型顏色
2) selectedColor:選擇字型顏色
3) borderStyle:tabbar上方線的顏色white(僅支援白色和黑色)
4) backgroundColor:tabbar背景顏色
5) list:設定rab清單項目(最少2個,最多5個tab)。
另外,list作為數組屬性,其每一項又是一個對象,list可以設定4種屬性:
① text:設定tab上的文字
② iconPath:設定tab處於未啟用狀態時顯示的圖片路徑。
③ selectedIconPath:設定tab處於啟用狀態時的圖片路徑(iconPath與selectedIconPath圖片大小限制都是40KB)
④ pagePath:設定觸按tab時的跳轉頁面路徑(該頁面必須在pages中進行了配置)
5、完整執行個體代碼點擊此處本站下載。
此外,小程式開發軟體如下:
https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/download.html?t=201714
希望本文所述對大家小程式開發有所協助。