【发布时间】:2017-06-28 19:08:46
【问题描述】:
我正在尝试使用自定义字体 Quicksand 创建一个应用程序(ionic 2)。
我的文件夹结构如下:
src
|
|-app
| |
| -app
| | |
| | -app.scss
| |
| -pages
| |
| -assets
| | |
| | -img
| | |
| | -fonts
| | | |
| | | -Quicksand-Bold.ttf
在我的app.scss 中,我有以下代码可以使字体在我的所有页面中都可用:
@font-face {
font-family: 'Quicksand-Bold';
font-style: normal;
font-weight: 300;
src: local('Quicksand-Bold'), local('Quicksand-Bold'), url("../assets/fonts/Quicksand-Bold.ttf") format('woff2');
unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
font-family: 'Quicksand-Bold';
font-style: normal;
font-weight: 300;
src: local('Quicksand-Bold'), local('Quicksand-Bold'), url("../assets/fonts/Quicksand-Bold.ttf") format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}
然后我可以在任何地方使用font-family: Quicksand-Bold 引用它。
这在 Android 和浏览器上运行良好,但无法在 iOS 上加载。
我在使用时遇到了问题:
background: url('../assets/img/background.jpg')
这导致我的 ios 应用程序崩溃。我为此使用的解决方法是使用图像创建一个div,并将其定位为背景图像。
当我引用 url("../assets/fonts/Quicksand-Bold.ttf") 时,我感觉这里发生了同样的事情,由于某种原因 iOS 无法找到指定的路径。
【问题讨论】:
-
试试 fontsquirrel:fontsquirrel.com/tools/webfont-generator
-
抛出一个
Http Status 500但它有什么作用? -
生成不同格式的字体。
-
这可能是 iOS 的问题吗?它不接受
.ttf格式? (因为它确实适用于 Android 和浏览器)因为根据这个答案,支持的唯一字体是OTF和TTFstackoverflow.com/questions/6277606/… -
是的。这可能会解决您的问题。