ionic4自定义底部Tab五个按钮的样式(按钮凸起效果)

ionic4自定义底部Tab五个按钮的样式

效果图

效果图
切换后的样式

实现代码

tabs.page.html代码.

<ion-tabs  (ionTabsDidChange)="tabchange($event)">
  <ion-tab-bar  slot="bottom" translucent="true">
    <ion-tab-button tab="tab1" [ngClass]="{'left-one-tab-active':tabname=='tab1','left-one-tab':tabname!='tab1'}">
      <ion-icon name="send" class="icon"></ion-icon>
    </ion-tab-button>
    <ion-tab-button tab="tab2" [ngClass]="{'left-two-tab-active':tabname=='tab2','left-two-tab':tabname!='tab2'}">
      <ion-icon name="apps" class="icon"></ion-icon>
    </ion-tab-button>
    <ion-tab-button tab="tab3" [ngClass]="{'center-tab-active':tabname=='tab3'||tabname==undefined,'center-tab':tabname!='tab3'}">
      <ion-icon name="send" class="icon"></ion-icon>
    </ion-tab-button>
    <ion-tab-button tab="tab2" [ngClass]="{'right-one-tab-active':tabname=='tab2','right-one-tab':tabname!='tab2'}">
      <ion-icon name="apps" class="icon"></ion-icon>
    </ion-tab-button>
    <ion-tab-button tab="tab1" [ngClass]="{'right-two-tab-active':tabname=='tab1','right-two-tab':tabname!='tab1'}">
      <ion-icon name="send" class="icon"></ion-icon>
    </ion-tab-button>
  </ion-tab-bar>
</ion-tabs>

tabs.page.html代码.

ion-tab-bar {--border: 0;height: 110px;}

ion-tab-button {
    --color: #8c8e8c;
    --color-selected: var(--color-bg-dark-theme);
}

.left-one-tab {
    position: absolute;
    overflow: visible;
    text-align: center;
    height: 80px;
    width: 20%;
    left: 15px;
    margin: auto;
    bottom: 4px;
    z-index: 99999;

    .icon {
        padding: 6px;
        background-color: #fff;
        color: #8c8e8c;
        border-radius: 50%;
        box-shadow: 0 9px 16px #b9c0c7;
    }
}
.left-one-tab-active {
    position: absolute;
    overflow: visible;
    text-align: center;
    height: 80px;
    width: 20%;
    left: 15px;
    margin: auto;
    bottom: 4px;
    z-index: 99999;

    .icon {
        padding: 6px;
        border-radius: 50%;
        background-image: linear-gradient(-45deg, var(--color-bg-dark-theme) 0%, var(--color-bg-theme) 90%);
        color: var(--ion-color-white, #fff);
        box-shadow: 0 9px 16px var(--color-bg-dark-theme);
    }
}

.left-two-tab {
    position: absolute;
    overflow: visible;
    text-align: center;
    height: 96px;
    width: 20%;
    left: 20%;
    // right: 0;
    margin: auto;
    bottom: 4px;
    z-index: 99999;

    .icon {
        padding: 6px;
        background-color: #fff;
        color: #8c8e8c;
        border-radius: 50%;
        box-shadow: 0 9px 16px #b9c0c7;
        margin-left: 10px;
    }
}
.left-two-tab-active {
    position: absolute;
    overflow: visible;
    text-align: center;
    height: 96px;
    width: 20%;
    left: 20%;
    margin: auto;
    bottom: 4px;
    z-index: 99999;

    .icon {
        padding: 6px;
        border-radius: 50%;
        margin-left: 10px;
        background-image: linear-gradient(-45deg, var(--color-bg-dark-theme) 0%, var(--color-bg-theme) 90%);
        color: var(--ion-color-white, #fff);
        box-shadow: 0 9px 16px var(--color-bg-dark-theme);
    }
}
.center-tab {
    position: absolute;
    overflow: visible;
    text-align: center;
    height: 110px;
    width: 20%;
    left: 0;
    right: 0;
    margin: auto;
    bottom: 4px;
    z-index: 99999;

    .icon {
        font-size: 3rem;
        padding: 6px;
        border-radius: 50%;
        background-color: #fff;
        color: #8c8e8c;
        box-shadow: 0 9px 16px #b9c0c7;
    }
}
.center-tab-active {
    position: absolute;
    overflow: visible;
    text-align: center;
    height: 110px;
    width: 20%;
    left: 0;
    right: 0;
    margin: auto;
    bottom: 4px;
    z-index: 99999;

    .icon {
        font-size: 3rem;
        padding: 6px;
        background-image: linear-gradient(-45deg, var(--color-bg-dark-theme) 0%, var(--color-bg-theme) 90%);
        color: var(--ion-color-white, #fff);
        border-radius: 50%;
        box-shadow: 0 9px 16px var(--color-bg-dark-theme);
    }
}

.right-one-tab {
    position: absolute;
    overflow: visible;
    text-align: center;
    height: 96px;
    width: 20%;
    right: 20%;
    margin: auto;
    bottom: 4px;
    z-index: 99999;

    .icon {
        padding: 6px;
        color: #8c8e8c;
        background-color: #fff;
        border-radius: 50%;
        box-shadow: 0 9px 16px #b9c0c7;
        margin-right: 10px;
    }
}
.right-one-tab-active {
    position: absolute;
    overflow: visible;
    text-align: center;
    height: 96px;
    width: 20%;
    right: 20%;
    margin: auto;
    bottom: 4px;
    z-index: 99999;

    .icon {
        padding: 6px;
        border-radius: 50%;
        margin-right: 10px;
        background-image: linear-gradient(-45deg, var(--color-bg-dark-theme) 0%, var(--color-bg-theme) 90%);
        color: var(--ion-color-white, #fff);
        box-shadow: 0 9px 16px var(--color-bg-dark-theme);
    }
}

.right-two-tab {
    position: absolute;
    overflow: visible;
    text-align: center;
    height: 80px;
    width: 20%;
    right: 15px;
    margin: auto;
    bottom: 4px;
    z-index: 99999;

    .icon {
        padding: 6px;
        color: #8c8e8c;
        background-color: #fff;
        border-radius: 50%;
        box-shadow: 0 9px 16px #b9c0c7;
    }
}
.right-two-tab-active {
    position: absolute;
    overflow: visible;
    text-align: center;
    height: 80px;
    width: 20%;
    right: 15px;
    margin: auto;
    bottom: 4px;
    z-index: 99999;

    .icon {
        padding: 6px;
        border-radius: 50%;
        background-image: linear-gradient(-45deg, var(--color-bg-dark-theme) 0%, var(--color-bg-theme) 90%);
        color: var(--ion-color-white, #fff);
        box-shadow: 0 9px 16px var(--color-bg-dark-theme);
    }
}

tabs.page.ts代码.

export class TabsPage {
  constructor() {}
  tabname:any= 'tab3';
  tabchange(e){
    this.tabname = e.tab;
  }
}

其中(ionTabsDidChange)="tabchange($event)"用来监听tab的变化,然后改变样式

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值