iOS custom font path for UIWebViews(UIWebViews 的 iOS 自定义字体路径)
问题描述
我有一个 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 自定义字体路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIWebViews 的 iOS 自定义字体路径
基础教程推荐
- Android文本颜色不会改变颜色 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
