微信小程序自定义顶部以及底部tabbar

1.首先建立一个模板,在里边模板的wxml里绘制公共的顶部以及底部
代码如下:

<!--pages/template/template.wxml-->
<template name="top">
<!-- 顶部 -->
   <view style="padding-top:{
  {topcontent.statusBarHeight+topcontent.titleBarHeight}}px;">
  <view class="hh-header" style='background-color:{
  {topcontent.background}};color:{
  {topcontent.color}};'>
    <view class="status-bar" style="height:{
  {topcontent.statusBarHeight}}px"></view>
    <view class="title-bar" style="height:{
  {topcontent.titleBarHeight}}px">
      <view wx:if="{
  {topcontent.isShowBack}}" class='hh-nav-back ico-back' bindtap='goback'></view>
      <view wx:if="{
  {!topcontent.isShowBack}}" class='hh-nav-back'></view>
      <view class="hh-title">{
  {topcontent.name}}</view>
      <view class="hh-nav-right"></view>
    </view>
  </view>
</view>
</template>
<!-- 底部 -->
<template name="tabbar">
    <view class="tabbar_box" style="background-color:{
  {tabbar.backgroundColor}}; border-top-color:{
  {tabbar.borderStyle}}; {
  {tabbar.position == 'top' ? 'top:0' : 'bottom:0'}}">
        <block wx:for="{
  {tabbar.list}}" wx:for-item="item" wx:key="index">
            <view class="tabbar_nav" style="width:{
  {1/tabbar.list.length*100}}%; " bindtap='switchTab' data-url='{
  {item.pagePath}}'>
                <image class="tabbar_icon" src="{
  {item.selected ? item.selectedIconPath : item.iconPath}}"></image>
                <text style="color:{
  {item.selected ? tabbar.selectedColor : tabbar.color}}">{
  {item.text}}</text>
            </view>
        </block>
    </view>
</template>

2.然后在模板的wxss里样式

 /* pa
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
微信小程序提供了自定义顶部 tabbar 的功能,你可以在 app.json 文件中的 "tabBar" 字段中进行配置。以下是一个示例: ```json { "tabBar": { "color": "#999999", "selectedColor": "#ff0000", "backgroundColor": "#ffffff", "borderStyle": "white", "list": [ { "pagePath": "pages/index/index", "text": "首页", "iconPath": "images/tabbar/home.png", "selectedIconPath": "images/tabbar/home_active.png" }, { "pagePath": "pages/category/category", "text": "分类", "iconPath": "images/tabbar/category.png", "selectedIconPath": "images/tabbar/category_active.png" }, { "pagePath": "pages/cart/cart", "text": "购物车", "iconPath": "images/tabbar/cart.png", "selectedIconPath": "images/tabbar/cart_active.png" }, { "pagePath": "pages/profile/profile", "text": "个人中心", "iconPath": "images/tabbar/profile.png", "selectedIconPath": "images/tabbar/profile_active.png" } ] } } ``` 在上面的示例中,你可以通过修改相应的字段来自定义顶部 tabbar。具体解释如下: - `color`:未选中的 tab 文字颜色 - `selectedColor`:选中的 tab 文字颜色 - `backgroundColor`:tab 背景色 - `borderStyle`:tab 边框线颜色,可选值为 "black"、"white" - `list`:tab 列表,每个对象代表一个 tab,包括以下字段: - `pagePath`:页面路径 - `text`:tab 文字 - `iconPath`:未选中的 tab 图标路径 - `selectedIconPath`:选中的 tab 图标路径 你可以根据自己的需求修改以上字段来实现自定义顶部 tabbar。注意,图标路径需要放在对应的目录下,并且需要在页面中使用相对路径引用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值