How to add custom image in tab-button-icon in ionic 3.

拥有回忆 提交于 2019-12-24 11:37:23

问题


I want to add my own custom images in place of default images provided by ionic3. I am new in Ionic please help me. Searching for solution since 1 week.

tabs.html

    <ion-tabs [selectedIndex]="mySelectedIndex" name="conference">
        <ion-tab [root]="tab1Root" tabsHideOnSubPages="false" tabTitle="Home" tabIcon="home"></ion-tab>
        <ion-tab [root]="tab2Root" tabsHideOnSubPages="false" tabTitle="About" tabIcon="information-circle"></ion-tab>
        <ion-tab [root]="tab3Root" tabsHideOnSubPages="false" tabTitle="Contact" tabIcon="contacts"></ion-tab>
    </ion-tabs>

tabs.ts

    import { Component } from '@angular/core';
    import { NavParams } from 'ionic-angular';
    import { AboutPage } from '../about/about';
    import { ContactPage } from '../contact/contact';
    import { HomePage } from '../home/home';

    @Component({
      templateUrl: 'tabs.html'
    })
    export class TabsPage {

      tab1Root = HomePage;
      tab2Root = AboutPage;
      tab3Root = ContactPage;
      mySelectedIndex: number;

      constructor(navParams: NavParams) {
        this.mySelectedIndex = navParams.data.tabIndex || 0;
      }
    }

回答1:


I have been looking into this for almost 2 hours. You can simply use following snippet.

  <ion-tab 
    [root]="tab1Root" 
    tabIcon="customicon">
   </ion-tab>
ion-icon {
        background-repeat: no-repeat;
        background-position: 50%;
        background-size: contain;
        background-size: 18px;

        &[ng-reflect-name="customicon"] {
            background-image: url('../assets/images/<your-image>.inactive.png');
            &[ng-reflect-is-active="true"] {
                background-image: url('../assets/images/<your-image>.active.png');
            }
        }
}


来源:https://stackoverflow.com/questions/47152672/how-to-add-custom-image-in-tab-button-icon-in-ionic-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!