新聞中心
小編給大家分享一下微信小程序中tabBar的使用方法,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
微信小程序tabBar用法,結(jié)合實(shí)例形式詳細(xì)分析了微信小程序中tabBar的功能、配置項(xiàng)使用方法與操作注意事項(xiàng)
1、效果展示
2、原理:在app.json中配置tabBar屬性
{ "pages": [ "index", "picDisplay" ], "window": { "navigationBarBackgroundColor": "#ffffff", "navigationBarTextStyle": "black", "navigationBarTitleText": "首頁(yè)", "backgroundColor": "#eeeeee", "backgroundTextStyle": "light", "enablePullDownRefresh": false }, "tabBar": { "color":"#666666", "selectedColor":"#06bd04", "list": [{ "pagePath": "index", "text": "首頁(yè)", "iconPath": "images/index.png", "selectedIconPath": "images/indexHL.png" },{ "pagePath": "picDisplay", "text": "圖片展示", "iconPath": "images/picDisplay.png", "selectedIconPath": "images/picDisplayHL.png" }] } }
3、關(guān)鍵代碼
"tabBar": { "color":"#666666", "selectedColor":"#06bd04", "list": [{ "pagePath": "index", "text": "首頁(yè)", "iconPath": "images/index.png", "selectedIconPath": "images/indexHL.png" },{ "pagePath": "picDisplay", "text": "圖片展示", "iconPath": "images/picDisplay.png", "selectedIconPath": "images/picDisplayHL.png" }] }
4、操作方法
新建一個(gè)項(xiàng)目,打開app.json文件,將關(guān)鍵代碼復(fù)制到"window":{},后面,注意window的大括號(hào)前加逗號(hào),如下圖
配置tabBar屬性值
"tabBar": { //設(shè)置tabBar文字默認(rèn)顏色 "color":"#666666", //設(shè)置tabBar文字被選中是的顏色 "selectedColor":"#06bd04", //tab列表,數(shù)組類型,改數(shù)組內(nèi)至少要有兩個(gè)但不大于5個(gè)的tab對(duì)象 "list": [{ //設(shè)置tab跳轉(zhuǎn)頁(yè)面鏈接 "pagePath": "index", //設(shè)置tab上的文字 "text": "首頁(yè)", //設(shè)置tab上的默認(rèn)圖標(biāo) "iconPath": "images/index.png", //設(shè)置tab被選中時(shí)的圖標(biāo) "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:設(shè)置rab列表項(xiàng)(最少2個(gè),最多5個(gè)tab)。
另外,list作為數(shù)組屬性,其每一項(xiàng)又是一個(gè)對(duì)象,list可以設(shè)置4種屬性:
① text:設(shè)置tab上的文字
② iconPath:設(shè)置tab處于未激活狀態(tài)時(shí)顯示的圖片路徑。
③ selectedIconPath:設(shè)置tab處于激活狀態(tài)時(shí)的圖片路徑(iconPath與selectedIconPath圖片大小限制都是40KB)
④ pagePath:設(shè)置觸按tab時(shí)的跳轉(zhuǎn)頁(yè)面路徑(該頁(yè)面必須在pages中進(jìn)行了配置)
看完了這篇文章,相信你對(duì)“微信小程序中tabBar的使用方法”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
分享文章:微信小程序中tabBar的使用方法-創(chuàng)新互聯(lián)
當(dāng)前URL:http://www.ef60e0e.cn/article/ddeoed.html