iOS UIWebView完全看不懂不止一个@font-face?

iOS UIWebView totally fails to understand more than one @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"有效,另一个好像是"cancelled"。那么这里..

@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"有效,另一个好像是"cancelled".

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> 元素开头。这将使解析器关闭;显然它认为第一个 } 之前的所有内容都是不好的,需要丢弃。

解决方案:从<style>中取出<meta>