我有一个 UIWebView,我有一个自定义字体我想加载到一个可编辑的 html 文档中,我将通过 UIWebView 显示它.在我的 SupportingFiles(资源)文件夹中,我有Nosifer-Regular.ttf"...要在我的 HTML 中使用自定义字体,我需要字体拼贴的路径(URL)...我试过这样做,但它没有似乎不起作用...有什么想法吗?
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];
HTML (CSS):
The HTML (CSS):
@font-face {
font-family: 'Nosifer';
font-style: normal;
font-weight: 400;
src: local('Nosifer'), local('Nosifer-Regular'), url('%@') format('truetype');
}
%@ 替换为path_font"(在上面的第一个代码块中定义)
Where %@ is replaced with "path_font" (defined above in the first code block)
首先,在你的info.plist
中添加应用程序提供的字体"字段.它将是一个类似
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
什么的.
在 HTML 中使用 font-face 添加字体.并将您的字体文件与 html 文件放在同一目录中.如果 HTML 是动态生成的并且没有从 bundle 中显示,那么你应该复制字体.
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 .
祝你好运.
这篇关于UIWebViews 的 iOS 自定义字体路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!