微信小程序自定义导航栏

1.获取状态栏高度

    在app.js里面
     globalData: {
        statusBarHeight: wx.getSystemInfoSync()['statusBarHeight']//获取状态栏高度
      },

2.设置自定义导航栏标识

     "window": {
        "navigationStyle":"custom"
      },

3.设置样式
在app.wxss里面

    .custom{
      position: fixed;
      width: 100%;
      top: 0;
      left: 0;
      height: 45px;
      background: #2C5CFF;
      z-index: 999;
      display: flex;
      align-items: center;
    }
    .custom text{
      color: #fff;
      font-size: 34rpx;
      font-weight: 500;
      max-width: 280rpx;
    }
    .empty_custom{
      height: 45px;
      width: 100%;
    }

4.在页面自定义导航栏
在index.wxml自定义结构

    <view class="custom flex_center" style="padding-top:{{statusBarHeight}}px">
      <text>demo</text>
    </view>
    <view class="empty_custom" style="padding-top:{{statusBarHeight}}px"></view>

5.在index.js取出statusBarHeight的值

    Page({
        data:{
            statusBarHeight: app.globalData.statusBarHeight
        }
    })

基本上已经ok 不过会出现一个报错 app is not defined 还是没有出现状态栏

解决方案:在index.js顶部加上 var app = getApp(); 这样就好了…

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值