uni小程序安全头部和底部 高度

10 篇文章 0 订阅
2 篇文章 0 订阅

安全头部

小程序中的胶囊高度是40像素左右,从获取系统信息中可以看到:手机状态栏的高度,
到这里我们就可以算出在这里插入图片描述到胶囊底部的距离;
接下来是我自己写的头部组件:
在components文件夹里新建一个topNavbar.vue
在这里插入图片描述

`tempalte`
<template>
	<view :style="[allHeight]">
		<view class="fixBox">
			<view :style="[safeStyle]"></view>
			<view class="flexstart mleft" :style="'background:'+bgColor+';color:'+bgColor">
				//这个替换成自己的返回图标
				<u-icon v-if="isBack" class="backImg" size="20" name="arrow-left" :color="textColor" @click="backPage()"></u-icon>
				<view class="navCss" :style="'background:'+bgColor+';color:'+textColor">{{title}}</view>
			</view>
		</view>
		<view class="">
			<view :style="[safeStyle]"></view>
			<view class="navCss mleft" :style="'background:'+bgColor+';color:'+bgColor">{{title}}</view>
		</view>
	</view>
</template>
`script`
<script>
	export default {
		data() {
			return {}
		},
		props: {
			title: {//头部标题
				default: '标题'
			},
			bgColor: {//头部背景色
				default: "#3F85FF"
			},
			textColor: {//标题颜色
				default: "#fff"
			},
			isBack:{//是否展示返回按钮
				default: false,
			}
		},
		computed: {
			safeStyle() {
				const style = {}
				style.height = uni.getSystemInfoSync().statusBarHeight + 'px'
				style.backgroundColor = this.bgColor
				return style
			},
			allHeight(){
				const style = {}
				style.height = (uni.getSystemInfoSync().statusBarHeight + 40) + 'px'
				return style
			}
		},
		methods:{
			backPage(){
				// 返回上一页
				if(this.isBack){
					uni.navigateBack()
				}
			},
		}
	}
</script>

<style lang="less" scoped>
	.fixBox{
		position: fixed;
		top: 0;
		left: 0;
		width: 100vw;
		z-index: 2;
	}
	.backImg{
		font-size: 40rpx;
		padding-right: 32rpx;
	}
	.navCss {
		height: 40px;
		line-height: 40px;
	}
	.mleft{
		padding-left: 32rpx;
	}
	.flexstart{
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}
</style>

使用方法

//template
   <topNavbar title='会员中心' :textColor='textcolor' :bgColor="bgColor" :isBack="backShow"/>
//script 导入并注册
import navbottom from '@/components/navbottom.vue'
export default {
	data(){
		return{
			textcolor: '#ffffff',//标题颜色
			bgColor: 'rgba(36, 36, 48, 1)',//背景色
			backShow:false,//是否显示返回按钮
		}
	},
	components:{topNavbar}
}

安全底部

在这里插入图片描述

padding-bottom: env(safe-area-inset-bottom);
//为了适配有些机型底部是没有小横线的 可以采取下面的措施;更详细点可以通过获取机型 api 生成合适的底部距离
padding-bottom: calc(env(safe-area-inset-bottom) + 6px);

后续新加了一些自定义项,都上传到了DCloud插件市场了

已上传DCloud插件市场

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uni-app中,你可以通过以下步骤来实现自定义底部tabbar: 1. 在main.js文件中添加以下代码段,以解决点击两次才能选择icon的问题: ``` Vue.mixin({ methods: { setTabBarIndex(index) { if (typeof this.$mp.page.getTabBar === 'function' && this.$mp.page.getTabBar()) { this.$mp.page.getTabBar().setData({ selected: index }) } } } }) ``` 2. 在index.wxss文件中重新定义tabbar的样式,包括背景、高度、字体大小等。以下是一个例子: ```css .tab-bar { position: fixed; bottom: 0; left: 0; right: 0; display: flex; box-shadow: 0px -2px 10px 0px rgba(0,0,0,0.05); box-sizing: content-box; } .tab-bar-item { flex: auto; text-align: center; display: flex; justify-content: center; align-items: center; flex-direction: column; background: #fff; height: 120rpx; } /* 自定义样式 */ .tab-bar-item.diy { margin-top: 0!important; background: transparent; position: relative; flex: inherit; width: 134rpx; } .tab-bar-item image { width: 48rpx; height: 48rpx; overflow: initial; } .tab-bar-item view { font-size: 24rpx; } .tab-bar-item image.diy { position: absolute; width: 134rpx; height: 140rpx; bottom: 25.6%; z-index: 100; } .tab-bar-item view.diy { margin-top: 90rpx; background: #fff; width: 100%; height: 100%; padding-top: 58rpx; z-index: 99; } ``` 通过以上步骤,你可以在uni-app中实现自定义底部tabbar。使用以上的代码段和样式定义,你可以根据需求自定义底部tabbar的样式和交互效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [uni-app-tabbar:uni-app底部初步实现(不支持小程序)](https://download.csdn.net/download/weixin_42172572/15923240)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [uni-app自定义底部tabbar](https://blog.csdn.net/Janent168/article/details/129809136)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值