【问题标题】:Custom Fonts in Ionic3Ionic3 中的自定义字体
【发布时间】:2017-09-15 09:16:33
【问题描述】:

我正在使用Ionic3

Your system information:

Cordova CLI: 6.4.0 
Ionic Framework Version: 3.0.1
Ionic CLI Version: 2.1.18
Ionic App Lib Version: 2.1.9
Ionic App Scripts Version: 1.3.0
ios-deploy version: Not installed
ios-sim version: Not installed
OS: macOS Sierra
Node Version: v6.9.4
Xcode version: Xcode 8.3.1 Build version 8E1000a

我有以下字体:Ormont_Light.ttf

正如您在上面看到的,我尝试在app.scss 文件中应用这个新字体。但是,我似乎无法使其生效。

如您所见,它仍然使用 Ionic 默认值:

font-family: "Roboto", "Helvetica Neue", sans-serif;

问题

请任何人建议如何在 Ionic 3 中使用 ttf 文件实现新字体?

更新

我添加以下内容:

@font-face {
font-family: Ormont_Light;
src: url(../assets/fonts/Ormont_Light.ttf) format("ttf");
 font-weight: normal;
 font-style: normal;
}
body {
    font-family: Ormont_Light !important;
}

现在我在源代码中显示了字体:

body {
    font-family: Ormont_Light !important;
} 

但它并没有像预期的那样在全球范围内应用到应用程序。

更新

variables.scss

$font-family-base: "Ormont_Light";
$font-family-ios-base: $font-family-base;
$font-family-md-base: $font-family-base;
$font-family-wp-base: $font-family-base;

谢谢,这样的作品。它现在也应用了Ormont_Light 我所有的风格,这很棒。即dom 现在有:

body {
    font-family: Ormont_Light !important;
}

但是显示的字体使用Times New Roman字体,我猜这是浏览器默认找不到引用的字体。所以我猜我的.ttf 文件的路径不正确。

你把.ttf文件放在哪里?

【问题讨论】:

  • 感谢您对此的更新。它极大地帮助了我

标签: angularjs angular ionic2 ionic3


【解决方案1】:

您需要覆盖 Ionic Sass Variables 。 您需要在src/theme/variables.scss 中添加此字体。

@font-face {
 font-family: 'Ormont_Light';
 src:url('../assets/fonts/Ormont_Light.ttf') format('truetype');
 font-weight: normal;
 font-style: normal;
}
$font-family-base: "Ormont_Light";
$font-family-ios-base: $font-family-base;
$font-family-md-base: $font-family-base;
$font-family-wp-base: $font-family-base;

【讨论】:

  • 工作就像一个魅力!
猜你喜欢
  • 2013-09-30
  • 2011-09-07
  • 2011-04-12
  • 2012-07-24
  • 2020-12-18
  • 2016-03-06
  • 2015-12-29
  • 2018-06-26
  • 1970-01-01
相关资源
最近更新 更多