gpt4 book ai didi

UIWebViews 的 iOS 自定义字体路径

转载 作者:可可西里 更新时间:2023-11-01 05:31:47 24 4
gpt4 key购买 nike

我有一个 UIWebView,我有一个自定义字体,我想加载到一个可编辑的 html 文档中,我将通过 UIWebView 显示该文档。在我的 SupportingFiles(资源)文件夹中,我有“Nosifer-Regular.ttf”...要在我的 HTML 中使用自定义字体,我需要字体图 block 的路径(URL)...我尝试这样做,但它没有似乎行不通……有什么想法吗?

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):

@font-face {
font-family: 'Nosifer';
font-style: normal;
font-weight: 400;
src: local('Nosifer'), local('Nosifer-Regular'), url('%@') format('truetype');
}

其中 %@ 替换为“path_font”(在上面第一个代码块中定义)

最佳答案

首先,在您的info.plist 中添加“应用程序提供的字体”字段。它将是一个类似的数组

item0 myFont.otf
item1 anotherFont.ttf

或者什么的。

在 HTML 中使用 font-face 添加字体。并将您的字体文件与 html 文件放在同一目录中。如果 HTML 是动态生成的并且未从包中显示,那么您应该复制字体。

祝你好运。

关于UIWebViews 的 iOS 自定义字体路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9014211/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com