iOS UIWebView完全不能理解多个@ font-face?
注意这个在本地UIWebView中显示的简单的css / html:
有模拟器显示它…
注意有两个@ font-face定义。
但是… 只有第二个工作。 如果你交换他们,只有第二个工作。
所以在这里 …
@font-face { font-family:'aaa'; src: local('SourceSansPro-Regular'), url('SourceSansPro-Regular.ttf') format('truetype'); } @font-face { font-family:'bbb'; src: local('SourceSansPro-BoldIt'), url('SourceSansPro-BoldItalic.ttf') format('truetype'); }
只有“BBB”的作品 ,另一个似乎是“取消”。 那么这里
@font-face { font-family:'bbb'; src: local('SourceSansPro-BoldIt'), url('SourceSansPro-BoldItalic.ttf') format('truetype'); } @font-face { font-family:'aaa'; src: local('SourceSansPro-Regular'), url('SourceSansPro-Regular.ttf') format('truetype'); }
只有“aaa”有效 ,另一个似乎是“取消”。
这里是如何在Swift中完成的,
// load a simple UIWebView (say, an "about" or "legal" screen) // base is in template.html import UIKit import WebKit class MinorWebView:UIViewController { @IBOutlet var wv:UIWebView! @IBInspectable var filename:String = "?" // for example, "about" for "about.html" ... func makeHtml() { print("making html for ... " ,filename) let ourSize = grid.yourSizeDecisionMechanism let sizeString = String(format:"%.0f", ourSize) let p1 = NSBundle.mainBundle().pathForResource("template", ofType: "html") var html:String = try! NSString(contentsOfFile:p1!, encoding:NSUTF8StringEncoding) as String let p2 = NSBundle.mainBundle().pathForResource(filename, ofType: "html") let content:String = try! NSString(contentsOfFile:p2!, encoding:NSUTF8StringEncoding) as String html = html.stringByReplacingOccurrencesOfString("STUFF", withString:content) html = html.stringByReplacingOccurrencesOfString("SIZEPOINTS", withString:sizeString) print("Made html like this ---\n" ,html ,"\n------") wv.loadHTMLString(html as String, baseURL:nil) } }
只需将“template.html”和“about.html”拖到项目中(就像使用图像一样); 确保他们有目标成员。
您在<style>
块中有错误:它以<meta>
元素开头。 这将抛出parsing器; 显然它认为一切到第一个}
是坏的,需要被丢弃。
解决scheme:从<style>
取出<meta>
<style>
。