关于icon的tabs-icons使用自定义png jpg图片

先看效果:
里面的图标都是我用png的图片展示的
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
scss:将图片定义到css中

ion-icon {
  &[class*="custom-"] {
    margin: 0 5px 0 0;
    vertical-align: middle;
    $sz: 20px;
    width: $sz;
    height: $sz;
  }
  // custom icons
  &[class*="home-on"] {
    background: url(../assets/imgs/tabs/icon-home-on.png) no-repeat 50% 50%;
    background-size: contain;
  }
  &[class*="home-off"] {
    background: url(../assets/imgs/tabs/icon-home-off.png) no-repeat 50% 50%;
    background-size: contain;
  }

  &[class*="contact-on"] {
    background: url(../assets/imgs/tabs/icon-contact-on.png) no-repeat 50% 50%;
    background-size: contain;
  }
  &[class*="contact-off"] {
    background: url(../assets/imgs/tabs/icon-contact-off.png) no-repeat 50% 50%;
    background-size: contain;
  }

  &[class*="notice-on"] {
     background: url(../assets/imgs/tabs/icon-notice-on.png) no-repeat 50% 50%;
     background-size: contain;
   }
  &[class*="notice-off"] {
    background: url(../assets/imgs/tabs/icon-notice-off.png) no-repeat 50% 50%;
    background-size: contain;
  }
  &[class*="owner-on"] {
    background: url(../assets/imgs/tabs/icon-onwer-on.png) no-repeat 50% 50%;
    background-size: contain;
  }
  &[class*="owner-off"] {
    background: url(../assets/imgs/tabs/icon-owner-off.png) no-repeat 50% 50%;
    background-size: contain;
  }
}

HTML: 添加tabs切换的方法,还有判断tabs选中的状态

<ion-tabs>
 <ng-container *ngFor = "let tabRoot of tabRoots;let i = index;">
    <ion-tab  (ionSelect)="onChange(i)" [root] = "tabRoot.root" tabTitle="{{tabRoot.tabTitle}}" 				tabIcon="{{ tabsIndex == i ? tabRoot.tabIconOn:tabRoot.tabIconOff }}"></ion-tab>
  </ng-container>
</ion-tabs>

ts:自定义tabRoots数组,tabIconOn为选中图片,tabIconOff为未选择图片

 tabsIndex;
    this.tabRoots = [{
      root: HomePage,
      tabTitle: '首页',
      tabIconOn: 'custom-home-on',
      tabIconOff: 'custom-home-off',
        index:0
    }, {
      root: ContactPage,
      tabTitle: '通讯录',
        tabIconOn: 'custom-contact-on',
        tabIconOff: 'custom-contact-off',
        index:1
    }, {
      root: NoticePage,
      tabTitle: '消息',
      tabIconOn: 'custom-notice-on',
        tabIconOff: 'custom-notice-off',
        index:2
    }, {
      root: MinePage,
      tabTitle: '我的',
        tabIconOn: 'custom-owner-on',
        tabIconOff: 'custom-owner-off',
        index:3
    }];

还有tabs切换的方法:

 onChange(e){
      this.tabsIndex =e;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值