app.scssファイルに、次のコードを追加します。
ion-icon {
&[class*="custom-"] {
// Instead of using the font-based icons
// We're applying SVG masks
mask-size: contain;
mask-position: 50% 50%;
mask-repeat: no-repeat;
background: currentColor;
width: 1em;
height: 1em;
}
// custom icons
&[class*="custom-icon1"] {
mask-image: url(../assets/img/customicon1.svg);
}
&[class*="custom-icon2"] {
mask-image: url(../assets/img/customicon2.svg);
}
&[class*="custom-icon3"] {
mask-image: url(../assets/img/customicon3.svg);
}
}
次に、テンプレートで、次のHTMLを使用してアイコンを作成できます。
<ion-icon class="custom-icon1"></ion-icon>
他の質問では、人々はフォントベースの方法を提案しています。ただし、何百ものアイコンを追加しない限り、この答えはそれほど複雑ではありません。注意点は、各画像が個別のリクエストとして送信されることです。フォントメソッドと同様に、すべての画像が1つのファイルに含まれているため、もう少し効率的です。
3つの税関アイコンの例
scssファイル
.tabbar, .tabs-ios, .tabs-md , .tabs-wp{
.tab-button-icon {
background-repeat:no-repeat;
background-position:center;
height:24px;
width:24px;
background-size:contain;
-webkit-background-size: contain;
-moz-background-size: contain;
-o-background-size: contain;
&:before {
display:none;
}
}
}
.tabs-ios {
a[aria-selected=false]{
.tab-button-icon[ng-reflect-name=categories], .tab-button-icon[aria-label="categories"] {
background-image: url(../assets/img/categories_inactive.png);
}
.tab-button-icon[ng-reflect-name=home], .tab-button-icon[aria-label=home] {
background-image: url(../assets/img/explore_inactive.png);
}
.tab-button-icon[ng-reflect-name=hot], .tab-button-icon[aria-label=hot] {
background-image: url(../assets/img/hot_inactive.png);
}
}
a[aria-selected=true] {
//führ eventuellen text
//span {
//color: #f00; //whatever colour you want to use for the text
//}
.tab-button-icon[ng-reflect-name=categories], .tab-button-icon[aria-label=categories] {
background-image: url(../assets/img/categories_active.png);
}
.tab-button-icon[ng-reflect-name=home], .tab-button-icon[aria-label=home] {
background-image: url(../assets/img/explore_active.png);
}
.tab-button-icon[ng-reflect-name=hot], .tab-button-icon[aria-label=hot] {
background-image: url(../assets/img/hot_active.png);
}
}
}
.tabs-md {
a[aria-selected=false]{
.tab-button-icon[ng-reflect-name=categories], .tab-button-icon[aria-label="categories"] {
background-image: url(../assets/img/categories_inactive.png);
}
.tab-button-icon[ng-reflect-name=home], .tab-button-icon[aria-label=home] {
background-image: url(../assets/img/explore_inactive.png);
}
.tab-button-icon[ng-reflect-name=hot], .tab-button-icon[aria-label=hot] {
background-image: url(../assets/img/hot_inactive.png);
}
}
a[aria-selected=true] {
//führ eventuellen text
//span {
//color: #f00; //whatever colour you want to use for the text
//}
.tab-button-icon[ng-reflect-name=categories], .tab-button-icon[aria-label=categories] {
background-image: url(../assets/img/categories_active.png);
}
.tab-button-icon[ng-reflect-name=home], .tab-button-icon[aria-label=home] {
background-image: url(../assets/img/explore_active.png);
}
.tab-button-icon[ng-reflect-name=hot], .tab-button-icon[aria-label=hot] {
background-image: url(../assets/img/hot_active.png);
}
}
}
.tabs-wp {
a[aria-selected=false]{
.tab-button-icon[ng-reflect-name=categories], .tab-button-icon[aria-label="categories"] {
background-image: url(../assets/img/categories_inactive.png);
}
.tab-button-icon[ng-reflect-name=home], .tab-button-icon[aria-label=home] {
background-image: url(../assets/img/explore_inactive.png);
}
.tab-button-icon[ng-reflect-name=hot], .tab-button-icon[aria-label=hot] {
background-image: url(../assets/img/hot_inactive.png);
}
}
a[aria-selected=true] {
//führ eventuellen text
//span {
//color: #f00; //whatever colour you want to use for the text
//}
.tab-button-icon[ng-reflect-name=categories], .tab-button-icon[aria-label=categories] {
background-image: url(../assets/img/categories_active.png);
}
.tab-button-icon[ng-reflect-name=home], .tab-button-icon[aria-label=home] {
background-image: url(../assets/img/explore_active.png);
}
.tab-button-icon[ng-reflect-name=hot], .tab-button-icon[aria-label=hot] {
background-image: url(../assets/img/hot_active.png);
}
}
}
Htmlファイル
<ion-tab [root]="tab2Root" tabIcon="categories"></ion-tab>
<ion-tab [root]="tab1Root" tabIcon="home"></ion-tab>
<ion-tab [root]="tab3Root" tabIcon="hot"></ion-tab>
ソースと詳細: https://forum.ionicframework.com/t/ionic2-tutorial-tabs-with-custom-active-inactive-icons/7516