uniapp 实现tabbar图标凸起

实现tabbar图标凸起有两种,第一种是自定义tabbar,第二种就是使用官方的tabbar跟api实现,自定义在体验中不如原生的tabbar,所以我下面展示的是使用官方的tabbar跟api实现

效果如图:

左边是未选中中间的凸起,右边是选中中间凸起,有一个问题就是我们选中凸起后文字颜色没有改变,目前我还没找到解决方案,有办法的兄弟们 可以留言

代码实现

tabbar

"tabBar": {
		"borderStyle": "white",
		"backgroundColor": "white",
		"color": "#8F8F94",
		"selectedColor": "#e3b23e",
		"list": [{
				"pagePath": "pages/xxxx/xxxx",
				"iconPath": "static/uni.png",
				"selectedIconPath": "static/uni.png",
				"text": "主页"
			},
			{
				"pagePath": "pages/xxxx/xxxx",
				"iconPath": "static/uni.png",
				"selectedIconPath": "static/uni.png",
				"text": "积分榜"
			},
			{
				"pagePath": "pages/xxxx/xxxx",
				"iconPath": "static/c8.png",
				"selectedIconPath": "static/uni.png",
				"text": "订阅/下单",
				"visible": false
			},
			{
				"pagePath": "pages/xxxx/xxxx",
				"iconPath": "static/uni.png",
				"selectedIconPath": "static/uni.png",
				"text": "任务"
			},
			{
				"pagePath": "pages/xxxx/xxxx",
				"iconPath": "static/uni.png",
				"selectedIconPath": "static/uni.png",
				"text": "我的账户"
			}
		],
		"midButton": {
			"iconPath": "static/c8.png",
			"iconWidth": "60px",
			"height": "80px",
			"text": "订阅/下单"
		}
	}

midButton  中间按钮 仅在 list 项为偶数时有效,官方说明:

 pages.json 页面路由 | uni-app官网

 监听点击中的tabbar,并修改图标为选中状态  app.vue中监听

// 点击中间按钮  
			uni.onTabBarMidButtonTap(() => {
				console.log('中间')
				uni.setTabBarStyle({
					midButton: {
						"iconPath": "static/uni.png",
						"iconWidth": "60px",
						"height": "80px",
						"text": "订阅/下单",
						"color": "red"
					}
				})
				uni.switchTab({
					url: '/pages/xxx/xxx'
				})
			})

然后在其他的tabbar list的页面监听tabbar点击,点击不是中间tabbar,为其他tabbar时 将中间tabbar又改为未选中状态

<script>
	import {
		onTabItemTap
	} from "@dcloudio/uni-app"
	import {} from 'vue';

	export default {
		setup() {
			onTabItemTap((e) => {
				uni.setTabBarStyle({
					midButton: {
						"iconPath": "static/c8.png",
						"iconWidth": "60px",
						"height": "80px",
						"text": "订阅/下单"
					}
				})
			})

			return {
			};
		}
	};
</script>

  • 9
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

来自湖南的阿晨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值