问题描述
我想在UIWebView中显示自定义字体。我已经将字体放在应用程序提供的字体下的plist中。正在使用的代码:pre $ $ $ c $ 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 =0topmargin =0>
这是< i>斜体< / i>并且这是< b>粗体< / b>这是一个unicode:&#1101;
< / body>< / html>
我使用的是iOS 4.2,所以应该支持TTF。我会很感激一些HTML /代码,实际上工作。
经过一些尝试和错误,我找到了一个可靠的方法使用本地CSS加载自定义字体。
1。添加您的字体到应用程序...确保该文件的目标
正确的应用程序
2。然后将你的字体添加到yourApp-Info.plist中
$ b
3。运行 NSLog(@Available fonts:%@,[UIFont familyNames]);
检查系统字体/ fontfamily的名称...
$ /
。复制该名称并在CSS中使用它们... @ font-face不是必需的
pre $ body $ {
字体 - 家族:解放线;
}
I would like to display a custom font inside a UIWebView. I have already put the font in the plist under "Fonts provided by application". The code in use:
UIWebView *webView = [[UIWebView alloc] initWithFrame:myRect];
NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
[webView loadHTMLString:html baseURL:baseURL];
[self addSubview:webView];
where html is an NSString that has the following contents:
<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>
I'm using iOS 4.2 so TTF should be supported. I'd appreciate a bit of html/code that actually works.
After some Try and Error I have found a reliable way to load custom Fonts with a local CSS.
1. Add your Font to the App...make sure that the file is targeted properly to the Application
2. Then add your Font to yourApp-Info.plist
3. Run NSLog(@"Available fonts: %@", [UIFont familyNames]);
To check which name the font/fontfamily has for the System...
4. Copy that name and use them in your CSS...@font-face is not needed
body {
font-family:"Liberation Serif";
}
这篇关于在UIWebView中使用自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!