Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2 : Use picture in tab button

I use ion-tabs in my App and I want to use an picture in a tab-button. I want to set this picture dynamicly.

In my case, I have an account with different users linked to it. I want to change my tab picture depending of the selected user.

I have this :

enter image description here

And i want this :

enter image description here

My code in my tabs :

    <ion-tabs tabsHighlight="false">
      <ion-tab [root]="HomePage" 
               tabsHideOnSubPages="true"
               tabIcon="checkbox"
               tabTitle="A faire"
               tabBadge="5"
               tabBadgeStyle="notif">
      </ion-tab>
      <ion-tab [root]="ToComePage"
               tabsHideOnSubPages="true"
               tabIcon="time" tabTitle="A venir"
               tabBadge="0"
               tabBadgeStyle="notif">
      </ion-tab>
      <ion-tab [root]="HistoricPage"
               tabsHideOnSubPages="true"
               tabIcon="book"
               tabTitle="Historique">
      </ion-tab>
      <ion-tab [root]="MenuPage"
               tabsHideOnSubPages="true"
//I want to delete this tab Icon and replace it by a picture.
               tabIcon="menu"
               tabTitle="Menu">
      </ion-tab>
    </ion-tabs>

I don't know how to do that, an idea ?

like image 649
V. Pivet Avatar asked Feb 22 '17 08:02

V. Pivet


2 Answers

give custom name to tabIcon like

<ion-tab [root]="MenuPage"
       tabsHideOnSubPages="true"
       tabIcon="customicon"
       tabTitle="Menu">
</ion-tab>

and in css:

.ion-ios-customicon-outline,
.ion-ios-customicon,.ion-md-customicon,.ion-md-customicon-outline {
  content: url('imageurl');
}

plunk

like image 111
varun aaruru Avatar answered Oct 29 '22 15:10

varun aaruru


Finally I find a solution ! I just write in the created DOM.

I do like this :

updateAccountTab() : void {
      let array = document.getElementsByClassName('tabbar');
      let tabbar = array[0];
      let element = tabbar.childNodes[tabbar.childElementCount-1];
      if(element) {
          element.removeChild(element.childNodes[1]);
          let img = document.createElement("img");
          img.setAttribute("class", "tab-icon-custom tab-button-icon icon icon-md");
          img.setAttribute("src", this.pdata.user.profile_thumbnail);
          element.insertBefore(img, element.childNodes[1]);
      }
  }
like image 27
V. Pivet Avatar answered Oct 29 '22 14:10

V. Pivet