Table of contents
Introduction to custom navigation bar:
step1: Cancel the default native navigation bar
Step2: Add placeholder elements to the page
Introduction to custom navigation bar:
It is generally used for filling pictures, etc. or other special needs. If you use a solid color to fill the top bar, you can directly use navigationBarBackgroundColor to complete it.
page.json file:
"navigationBarBackgroundColor": "#FED000"
Effect:
Use of custom navigation bar
step1: Cancel the default native navigation bar
Add code to the style of the page.json file page
"navigationStyle":"custom"
Step2: Add placeholder elements to the page
Footprints include:
<!-- 状态栏高度 -->
<view :style="{ height: `${statusBarHeight}px` }"></view>
<!-- 自定义导航栏高度 并 居中 -->
<view :style="{
height: `${barHeight}px`,
'line-height': `${barHeight}px`,
'text-align': 'center',
}">
<text>评价</text>
</view>
onLoad() {
// 状态栏高度
this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
// 胶囊数据
const { top, height } = wx.getMenuButtonBoundingClientRect();
// 自定义导航栏高度 = 胶囊高度 + 胶囊的padding*2, 如果获取不到设置为38
this.barHeight = height ? height + (top - this.statusBarHeight) * 2 : 38;
},