font-awesome - 如何在 sap.ui.core.Icon 中显示 glyphicon/font-awesome?

标签 font-awesome sapui5 glyphicons

由于 SAPUI5/OpenUI5 中的图标集合非常有限,我想在 sap.ui.core.Icon 中显示字形图标和/或很棒的字体图标。

如何实现这一目标?

最佳答案

为了在现有控件中使用外部图标,您可以使用 sap.ui.core.IconPool 控件。该控件提供了 addIcon 方法来添加图标。

  1. 列表项

    在 CSS 中声明 font-face 标签

    font-face {
      font-family: 'My-Icons'; 
      src: url('_PATH_TO_EOT_FILE_');
      src: url('_PATH_TO_EOT_FILE_?#iefix') format('embedded-opentype'), /*?#iefix is required to be added to the end of the path of eot file here*/
         url('_PATH_TO_TTF_FILE_') format('truetype');
      font-weight: normal;
      font-style: normal;
    };
    

    如果您使用的是 font-awesome,您可以在 list 中包含 font-awesome 样式表。样式表将包含在字体声明中,有点像这样:

    @font-face {
     font-family: 'FontAwesome';
     src: url('../fonts/fontawesome-webfont.eot?v=4.7.0');
     src: url('../fonts/fontawesome-webfont.eot?#iefix&v=4.7.0') format('embedded-opentype'), url('../fonts/fontawesome-webfont.woff2?v=4.7.0') format('woff2'), url('../fonts/fontawesome-webfont.woff?v=4.7.0') format('woff'), url('../fonts/fontawesome-webfont.ttf?v=4.7.0') format('truetype'), url('../fonts/fontawesome-webfont.svg?v=4.7.0#fontawesomeregular') format('svg');
     font-weight: normal;
     font-style: normal;
    }
    
  2. 调用 sap.ui.core.IconPool.addIcon添加您图标。你可以声明 这在你的 Component.js 中

    sap.ui.define([
      "sap/ui/core/UIComponent",
      "sap/ui/core/IconPool"],
     function(UIComponent, IconPool){
      "use strict";
     return UIComponent.extend("com.sap.app.Component",{
     metadata : {
        manifest: "json"
     },
     init : function(){
        //call the init function of the parent
        UIComponent.prototype.init.apply(this, arguments);
        //Init Router
        this.getRouter().initialize();
    
        IconPool.addIcon("battery", "fa", {
            fontFamily : "FontAwesome",
            content : "f241" 
        });
      }
     }); 
    });
    
  3. 您现在可以在您的控件中使用此图标

    <mvc:View controllerName="com.sap.app.controller.App" 
      xmlns:mvc="sap.ui.core.mvc" 
      xmlns:core="sap.ui.core" 
      xmlns="sap.m">
      <core:Icon src="sap-icon://fa/battery" color="#031E48" ></core:Icon>
      <Button icon="sap-icon://fa/battery" press="onPress"></Button>
    </mvc:View>
    

您还可以引用此处的文档:https://help.sap.com/saphelp_uiaddon10/helpdata/en/21/ea0ea94614480d9a910b2e93431291/content.htm

关于font-awesome - 如何在 sap.ui.core.Icon 中显示 glyphicon/font-awesome?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43062459/

相关文章:

javascript - SAPUI5 应用程序中的输入字段失去焦点

javascript - SAPUi5 单选按钮选定的文本

javascript - SAPUI5:sap.m.Shell 和 sap.m.App 作为应用程序包装容器的优缺点是什么?

html - 使用 Bootstrap 字形图标时如何修复 "empty button"Web 可访问性错误

jsf - 字形图标无法正确显示

css - 在 WP 站点中加载字体 awesome 5 时出错

html - 在 Mailchimp 事件中使用 Font Awesome 图标

TinyMCE 从 <span> 和 <i> 元素中删除类

css - 为什么有些 FontAwesome 图标没有显示?

font-awesome - font-awesome 中的别名是什么?