问题描述
我试图添加自定义字体到我的PhoneGap应用程序,我尝试了两种方法,我在互联网上发现,他们不工作使用PhoneGap 3和Xcode 5。
I am trying to add a custom font to my PhoneGap application and I tried two methods I found on the internet and they don't work using PhoneGap 3 and Xcode 5.
-
使用CSS的 font-face 方法:
@font-face {
font-family: 'Droid Arabic Kufi';
src: url('fonts/DroidKufi-Regular.ttf');
}
body {
font-family: 'Droid Arabic Kufi';
}
使用Xcode info.plist 文件方法: / p>
Using Xcode info.plist file method:
-
首先,我在项目资源文件夹中添加 DroidKufi-Regular.ttf 。
然后在 info.plist 文件中添加了一个新行,名为由应用程序提供的字体
项目 DroidKufi-Regular.ttf
。
Then added a new row in the info.plist file called Fonts provided by application
with item called DroidKufi-Regular.ttf
. and still doesn't work.
因此,在viewDidLoad方法中,我添加了这行代码 [UIFont fontWithName:@Droid Arabic
So, in viewDidLoad method I added this line of code
[UIFont fontWithName:@"Droid Arabic Kufi" size:10.0];
but still not working.
推荐答案
这在我的应用程序。 'fonts'是css文件目录中的子目录。
This works in my app. 'fonts' is a subdirectory in the directory with the css file.
@font-face {
font-family: 'grenouille';
src: url('fonts/grenouille.eot');
src: local('☺'), url('fonts/grenouille.woff') format('woff'), url('fonts/grenouille.ttf') format('truetype'), url('fonts/grenouille.svg') format('svg');
font-weight: normal;
font-style: normal;
}
h1 {
font-family: "grenouille";
}
我不确定您是否需要所有这些文件,他们使用网站
如果您仍然有问题,请检查字母大小写,从名称中删除空格,然后尝试应用预安装的字体系列,以确保您的问题是字体而不是css
If you still have problems, check letter cases, remove spaces from names and try to apply a preinstalled font family to be sure that your problem is the font and not the css rules.
这篇关于如何在PhoneGap中添加自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!