padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
Systeminfo({success: res => {let safeArea = res.safeAreaInsets.bottom;}
})
uniapp自定义tabBar方案
一、pages.json文件中添加tarBar
二、把原生的tabBar隐藏起来
三、自定义一个tabBar组件
//重点代码
height: 50px;
padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部
padding-bottom: env(safe-area-inset-bottom); /*兼容 IOS>11.2*/
<template><view class="tab-bar"><viewv-for="(item, index) in list":key="index"class="tab-bar-item"@click="switchTab(item, index)"><imageclass="tab_img":src="selected === index ? item.selectedIconPath : item.iconPath"></image><view class="tab_text" :style="{ color: selected === index ? selectedColor : color }">{{ }}</view></view></view>
</template><script>
export default {props: {selected: {// 当前选中的tab indextype: Number,default: 0}},data() {return {color: '#A1A1A1',selectedColor: '#F8A400',list: [{pagePath: '/pages/pointsMall/pointsMall',text: '商城',iconPath: '/static/tab_icons/cate.png',selectedIconPath: '/static/tab_icons/cate-active.png'},{pagePath: '/pages/mine/mine',text: '我的',iconPath: '/static/tab_icons/my.png',selectedIconPath: '/static/tab_icons/my-active.png'}]};},methods: {switchTab(item, index) {console.log('item', item);console.log('index', index);Launch({url: item.pagePath});}}
};
</script><style lang="scss">
.tab-bar {position: fixed;bottom: -1px;left: 0;right: 0;background-color: transparent;display: flex;justify-content: center;align-items: center;border-top-right-radius: 20px;.tab-bar-item {height: 50px;padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部padding-bottom: env(safe-area-inset-bottom); /*兼容 IOS>11.2*/background: white;flex: 1;text-align: center;display: flex;justify-content: center;align-items: center;flex-direction: row;.tab_img {width: 50rpx;height: 50rpx;}.tab_text {font-size: 20rpx;margin-left: 9rpx;}}
}
.tab-bar-item:first-child {border-top-right-radius: 20px;
}
.tab-bar-item:last-child {border-top-left-radius: 20px;
}
</style>
四、引用组件
五、路由跳转
本文发布于:2024-01-30 18:25:01,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170661030221950.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |