gpt4 book ai didi

ios - 在 UIWebView 中使用自定义字体

转载 作者:IT王子 更新时间:2023-10-29 07:36:01 26 4
gpt4 key购买 nike

我想在 UIWebView 中显示自定义字体。我已经将字体放在“应用程序提供的字体”下的 plist 中。使用中的代码:

        UIWebView *webView = [[UIWebView alloc] initWithFrame:myRect];
NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
[webView loadHTMLString:html baseURL:baseURL];
[self addSubview:webView];

其中 html 是具有以下内容的 NSString:

<html><head>
<style type="text/css">
@font-face {
font-family: gotham_symbol;
src: local('GOTHAMboldSymbol_0.tff'), format('truetype')
}
body {
font-family: gotham_symbol;
font-size: 50pt;
}
</style>
</head><body leftmargin="0" topmargin="0">
This is <i>italic</i> and this is <b>bold</b> and this is some unicode: &#1101;
</body></html>

我使用的是 iOS 4.2,所以应该支持 TTF。如果能提供一些实际有效的 html/代码,我将不胜感激。

最佳答案

经过反复尝试,我找到了一种使用本地 CSS 加载自定义字体的可靠方法。

1.将您的字体添加到应用程序...确保该文件是有针对性的 正确应用

enter image description here enter image description here

2。然后将您的字体添加到您的App-Info.plist

enter image description here

3。运行 NSLog(@"Available fonts: %@", [UIFont familyNames]); 检查字体/字体系列在系统中的名称...

enter image description here

4.复制该名称并在您的 CSS 中使用它们...不需要@font-face

body {
font-family:"Liberation Serif";
}

关于ios - 在 UIWebView 中使用自定义字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10490696/

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