Ionic framework 在ionic2中使用带有选项卡的自定义图标
我需要在ionic 2中使用带有选项卡的自定义图标 此外,如果选择了选项卡,我需要更改标题颜色和图标 例如:Ionic framework 在ionic2中使用带有选项卡的自定义图标,ionic-framework,ionic2,ionicons,Ionic Framework,Ionic2,Ionicons,我需要在ionic 2中使用带有选项卡的自定义图标 此外,如果选择了选项卡,我需要更改标题颜色和图标 例如: 查看爱奥尼亚2的选项卡 请参阅使用自定义图标以及如何在选项卡上显示它们 另外,我认为您可以通过.animate类更改标题和图标的CSS属性 如果没有,则从浏览器窗口中检查元素,并查找在选择选项卡时发生更改的类。您可以通过爱奥尼亚服务在浏览器中运行您的项目这是我在论坛上找到的最简单的方法 在app.scss文件中,添加以下代码: ion-icon { &[class*="c
查看爱奥尼亚2的
选项卡
请参阅使用自定义图标以及如何在选项卡上显示它们
另外,我认为您可以通过.animate
类更改标题和图标的CSS属性
如果没有,则从浏览器窗口中检查元素,并查找在选择选项卡时发生更改的类。您可以通过爱奥尼亚服务在浏览器中运行您的项目这是我在论坛上找到的最简单的方法
在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>
在其他问题中,人们建议使用基于字体的方法。不过,这个答案使用起来要简单得多,只要你没有添加数百个图标,你就应该可以了。需要注意的是,每个图像都作为一个单独的请求发送,其中与字体方法一样,所有图像都包含在一个文件中,因此效率更高。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>
来源和更多详细信息:我认为我们无法使用自动取款机。请检查我的答案,我希望这能帮助您:)这在Android中不起作用。背景:彩色;涵盖所有内容当我使用ionic cordova run android-lc运行时,它可以正常工作,但在生产构建时图标不起作用。有解决办法吗?