问题描述
我有一个UIWebView,我有一个自定义字体,我想加载到一个可编辑的HTML文档,我将通过UIWebView显示。在我的SupportingFiles(资源)文件夹中,我有Nosifer-Regular.ttf...要在我的HTML中使用自定义字体,我需要路径(URL)到字体瓦...我试过这样做, t似乎工作...任何想法? bundle = [NSBundle mainBundle];
pathFont = [bundle bundlePath];
fontURL = [NSBundle pathForResource:@Nosifer-RegularofType:@ttfinDirectory:pathFont];
path_font = [fontURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
fileAppend = [[NSString alloc] initWithFormat:@file://];
path_font = [[NSString alloc] initWithFormat:@%@%@,fileAppend,path_font];
HTML(CSS):
@ font-face {
font-family:'Nosifer';
font-style:normal;
font-weight:400;
src:local('Nosifer'),local('Nosifer-Regular'),url('%@')格式('truetype');
}
其中%@被替换为path_font(在上面第一个代码中定义块)
首先,在 info.plist中添加应用程序提供的字体
。它将是一个数组像
$ p $ lt; code> item0 myFont.otf
item1 anotherFont.ttf
$ b
或者别的东西。
在HTML中使用font-face来添加字体。并将您的字体文件与HTML文件放在同一个目录中。如果HTML是动态生成的,而不是从包中显示,那么你应该复制字体。
祝你好运
I have a UIWebView and I have a custom font I want to load into an editable html document that I will be displaying through the UIWebView. In my SupportingFiles (resources) folder I have "Nosifer-Regular.ttf"... To use the custom font in my HTML I need the path (URL) to the font tile... I tried doing this, but it didn't seem to work... any ideas?
bundle = [NSBundle mainBundle];
pathFont = [bundle bundlePath];
fontURL = [NSBundle pathForResource:@"Nosifer-Regular" ofType:@"ttf" inDirectory:pathFont];
path_font = [fontURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
fileAppend = [[NSString alloc] initWithFormat:@"file://"];
path_font = [[NSString alloc] initWithFormat:@"%@%@", fileAppend, path_font];
The HTML (CSS):
@font-face {
font-family: 'Nosifer';
font-style: normal;
font-weight: 400;
src: local('Nosifer'), local('Nosifer-Regular'), url('%@') format('truetype');
}
Where %@ is replaced with "path_font" (defined above in the first code block)
First of all, add filed "Fonts provided by application" in your info.plist
. It will be an array like
item0 myFont.otf
item1 anotherFont.ttf
or something.
In HTML use font-face to add a font. And place your font files in the same directory with html file. If HTML is generated dynamically and not shown from bundle then you should copy font .
Good luck.
这篇关于UIWebViews的iOS自定义字体路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!