【发布时间】:2018-12-20 10:48:38
【问题描述】:
我在 Ionic3 的 ActionSheet 按钮中使用来自 Fontawesome 的自定义图标时遇到问题。
据我所知,您可以添加例如以下代码:
<i class="fas fa-ad"></i>
在您的操作表按钮的title/text 属性中,图标出现了。
但自从 Ionic 3 以来,title/text 属性仅限于字符串,这不再起作用。
我还尝试了将那些 fontawesome 图标作为 png,然后将它们用作自定义 css 背景,就像在这个 Stackoverflow Question 中一样,但这也不起作用。图像只是不显示。
所以我最终使用了 ionic 作为图标提供的那些 ionicons,如下所示:
import { Component } from '@angular/core';
import { Platform, ActionSheetController } from 'ionic-angular';
@Component({
templateUrl: 'basic.html'
})
export class BasicPage {
constructor(
public platform: Platform,
public actionsheetCtrl: ActionSheetController
) { }
openMenu() {
let actionSheet = this.actionsheetCtrl.create({
title: 'Albums',
cssClass: 'action-sheets-basic-page',
buttons: [
{
text: 'Delete',
role: 'destructive',
icon: !this.platform.is('ios') ? 'trash' : null,
handler: () => {
console.log('Delete clicked');
}
},
{
text: 'Share',
icon: !this.platform.is('ios') ? 'share' : null,
handler: () => {
console.log('Share clicked');
}
},
{
text: 'Play',
icon: !this.platform.is('ios') ? 'arrow-dropright-circle' : null,
handler: () => {
console.log('Play clicked');
}
},
{
text: 'Favorite',
icon: !this.platform.is('ios') ? 'heart-outline' : null,
handler: () => {
console.log('Favorite clicked');
}
},
{
text: 'Cancel',
role: 'cancel', // will always sort to be on the bottom
icon: !this.platform.is('ios') ? 'close' : null,
handler: () => {
console.log('Cancel clicked');
}
}
]
});
actionSheet.present();
}
}
你们知道如何在 ActionSheet Buttons 中添加 fontawesome 图标吗?我似乎找不到任何有用的帮助。
【问题讨论】:
-
您是否尝试过仅使用图标代码?
-
是的,仍然没有显示图标
标签: angular typescript ionic-framework ionic3 font-awesome