离子2:使用标签按钮中的图片

V. *_*vet 12 javascript tabs ionic2 angular

我在我的应用程序中使用离子标签,我想在标签按钮中使用图片.我想动态地设置这张照片.

在我的情况下,我有一个帐户与不同的用户链接.我想根据所选用户更改我的标签图片.

我有这个 :

在此输入图像描述

我想要这个:

在此输入图像描述

我的标签中的代码:

    <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>
Run Code Online (Sandbox Code Playgroud)

我不知道怎么做,这个想法?

var*_*uru 13

给予定制名称到tabIcon喜欢

<ion-tab [root]="MenuPage"
       tabsHideOnSubPages="true"
       tabIcon="customicon"
       tabTitle="Menu">
</ion-tab>
Run Code Online (Sandbox Code Playgroud)

并在CSS中:

.ion-ios-customicon-outline,
.ion-ios-customicon,.ion-md-customicon,.ion-md-customicon-outline {
  content: url('imageurl');
}
Run Code Online (Sandbox Code Playgroud)

普拉克


V. *_*vet 3

最后我找到了解决方案!我只是在创建的 DOM 中写入。

我确实喜欢这样:

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]);
      }
  }
Run Code Online (Sandbox Code Playgroud)

  • 哦好的。今天晚些时候,我将编辑您的答案并包含 _ionic 方式_ 来执行完全相同的操作:) (2认同)