add my custom icons to ionic 2 actionSheet#39;s buttons(将我的自定义图标添加到 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 的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将我的自定义图标添加到 ionic 2 actionSheet 的按钮


- Fetch API 如何获取响应体? 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 400或500级别的HTTP响应 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06