【发布时间】:2012-05-16 11:15:57
【问题描述】:
我想在 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: э
</body></html>
我使用的是 iOS 4.2,所以应该支持 TTF。我会很感激一些实际有效的 html/代码。
【问题讨论】:
-
GOTHAMboldSymbol_0.tff- 扩展名应该是ttf(除非该字体在磁盘上确实有tff扩展名)。 -
我也在努力寻找解决方案,但是:我认为你想为 baseURL 传递 'nil'。
-
@Joris 我现在也遇到了同样的问题,如果你找到了解决方案,我会很高兴。
-
我在下面发布了我的 html...让我知道它是否适合您
标签: ios uiwebview fonts truetype