我想在UIWebView中顯示自定義字體。我已經將字體放在「應用程序提供的字體」下的plist中。使用代碼:在UIWebView中使用自定義字體
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'零'。 – MusiGenesis
@Joris我現在正面臨同樣的問題,如果您找到了解決方案,聽聽會很有趣。 – Lindemann