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 自定义字体路径
基础教程推荐
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
