本文介紹了將我的自定義圖標添加到 ionic 2 actionSheet 的按鈕的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我找不到將自定義圖標添加到 ionic 2/3 actionSheet 的方法.
I couldn't find a way to add my custom icon to ionic 2/3 actionSheet.
presentActionSheet() {
let actionSheet = this.actionSheetCtrl.create({
title: 'Mode',
buttons: [
{
text: 'Add to Y' ,
role: 'destructive',
icon:"my_icon",
cssClass:"yoy",
handler: () => {
console.log('Destructive clicked');
}
},
{
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
}
],
});
actionSheet.present();
}
如何將我自己的自定義圖標添加到操作表按鈕?
How can I add my own custom icons to the actionsheet buttons?
推薦答案
ionic doc 似乎沒有提出任何本地方法來做到這一點.但是,有一種方法可以使用自定義類來實現.
The ionic doc doesn't seem to propose any native way to do this. However, there is a way to achieve it using a custom class.
let actionSheet = this.actionSheetCtrl.create({
title: 'Mode',
buttons: [
{
text: 'Add to Y',
// vvvvv set a custom class that will be used to display the icon
cssClass: "class_used_to_set_icon",
handler: () => {
console.log('Add to Y clicked');
}
}
],
});
actionSheet.present();
然后在您的 src/app/app.scss 中定義以下類:
Then in your src/app/app.scss define the following class:
.class_used_to_set_icon {
// I'd suggest to have the icon in src/assets (eg ../assets/icon/favicon.ico)
background-image: url("path/to/your/icon") !important;
// to properly position the icon:
background-repeat: no-repeat !important;
background-position: 10px 10px !important;
// to indent the text to the right of the icon:
padding-left: 70px !important;
}
編輯
另一種使用來自 icomoon 等字體的自定義圖標的方法:
EDIT
Another way using custom icons from a font like icomoon:
let actionSheet = this.actionSheetCtrl.create({
title: 'Mode',
buttons: [
{
text: 'Add to Y',
// vvvvv set the custom icon class and a custom class to then improve display
cssClass: "icon-drink actionSheet_withIcomoon",
handler: () => {
console.log('Add to Y clicked');
}
}
],
});
actionSheet.present();
然后在您的 src/app/app.scss 中定義以下類:
Then in your src/app/app.scss define the following class:
// display the icon at the right size
.actionSheet_withIcomoon { font-size: 2.4rem !important; }
// correct the font dimensions and positioning of the text
.actionSheet_withIcomoon .button-inner {
font-family: "Roboto", "Helvetica Neue", sans-serif;
font-weight: bold;
padding-left: 52px;
margin-top: -20px;
font-size: 1.6rem !important;
}
這篇關于將我的自定義圖標添加到 ionic 2 actionSheet 的按鈕的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!