其中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中
$ b3。运行 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中使用自定义字体
发布评论