微信小程序自定义导航栏

如果你想自定义导航栏,只是让文字在不同机型之间一直处于与右侧小胶囊对齐的状态,这篇博客可能会对你有帮助
实现:
文字的margin-top = 小胶囊的top + (小胶囊的高度-文字的高度 / 2) 单位给px
效果:
iphone6/7/8
在这里插入图片描述
iphoneX
在这里插入图片描述
XR Max
在这里插入图片描述
代码:

<text :style="{ marginTop: customStatusBarHeight + 'px'}" class="header-title">康复云平台</text>
 ......
 ......
		onLoad() {
			wx.getSystemInfo({
				success: () => {
					const { height, top} = wx.getMenuButtonBoundingClientRect(); //结构右上角小胶囊的布局信息
					this.customStatusBarHeight = top + ((height - 18) / 2); // 赋值高度
				},
			});
		},
		data() {
			return {
				customStatusBarHeight: 0, // 自定义导航栏的marginTop
			};
		}

样式微调就可以
如果想要一个更逼真的导航栏可以这样

<view class="" style="background-color: #1CBBB4;width: 100%;" :style="{height: customNavigationBarHeight + 'px'}">
		</view>
onLoad() {
			wx.getSystemInfo({
				success: (res) => {
					const { height, top} = wx.getMenuButtonBoundingClientRect();
					this.customNavigationBarHeight = height + top + 6;
				},
			});
		},
		data() {
			return {
				customNavigationBarHeight: 0
			}
		},

iphone5
在这里插入图片描述
iphone6/7/8
在这里插入图片描述
iphone x

在这里插入图片描述

最后,如果本文对你有帮助,可以关注我的公众号,上面有前端电子书,等学习资源,来找我玩啊
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值