关于uniapp自定义标题栏,高度自适应对齐方案解决

	给我们需要自定义的页面进行配置"navigationStyle":"custom"

在这里插入图片描述

在这里插入图片描述

关于ios和Android状态栏高度不一致声明:ios标题栏高度为44px,Android为46px;

html代码:

<view class="content-fixed">
	<view v-if="platform === 'ios'">
		<view class="status_bar" :style="'height:' + statusBarHeight + 'px;'">
		</view>
		<view class="navbar-title" style="height: 44px;">
			<image style="width: 186upx;height: 68upx;margin-left: 34upx;" src="../../static/home-title.png"></image>
			<view class="title-icon" @click="toCustorm">
				<image class="customer-service" src="../../static/customer-service.png"></image>
			</view>
		</view>
	</view>
	<view v-if="platform === 'android'">
		<view class="status_bar" :style="'height:' + statusBarHeight + 'px;'">
			  <!-- 这里是状态栏 -->
		</view>
		<view class="navbar-title">
			<image style="width: 186upx;height: 68upx;margin-left: 34upx;" src="../../static/home-title.png"></image>
			<view class="title-icon" @click="toCustorm">
				<image class="customer-service" src="../../static/customer-service.png"></image>
			</view>
		</view>
	</view>
</view>

状态栏可通过uniapp的uni.getSystemInfo动态获取;代码如下

const that = this
//获取手机型号
uni.getSystemInfo({
    success: function (res) {
		that.statusBarHeight = res.statusBarHeight//状态栏高度
		that.platform = res.platform//机型
    }
});

css:

.content-fixed {
width: 100%;
	position: fixed;
	top: 0;
	background: linear-gradient(180deg, #fa2828 0%, #fa3d38 100%);
	z-index: 9999;
}
.status_bar {
     height: var(--status-bar-height);
     width: 100%;
 }
 .navbar-title {
	 width: 100%;
	 height: 46px;
	 color: #FFFFFF;
	 font-size: 64upx;
	 display: flex;
	 justify-content: space-between;
	 align-items: center;
	 // position: fixed;
	 // top: 44upx;
	 .title {
	 	margin-left: 34upx;
	 }
	 .title-icon {
		width: 64upx;
		height: 64upx;
		border-radius: 32upx;
		background-color: rgba(36, 36, 36, 0.2);
		display: flex;
		justify-content: center;
		align-items: center;
		/* #ifdef MP-WEIXIN */
		margin-right: 210upx;
		/* #endif */
		/* #ifdef APP-PLUS */
		margin-right: 30rpx;
		/* #endif */
		vertical-align: middle;				
		.customer-service {
			width: 40upx;
			height: 40upx;
			uni-image {
				width: 40upx;
				height: 40upx;
			}
		}
		
	 }
 }
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值