iOS UIWebView完全不能理解多个@ font-face? [英] iOS UIWebView totally fails to understand more than one @font-face?

查看:709
本文介绍了iOS UIWebView完全不能理解多个@ font-face?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意这个简单的css / html是显示在本地UIWebView:

Notice this simple css/html which is being displayed in a local UIWebView:

有模拟器显示它...

there's the simulator showing it...

注意有两个@ font-face定义。

Notice there are two @font-face definitions.

但是... 只有第二个工作。 如果你把它们交换,只有第二个工作。

But ... only the second one works. If you swap them around, only the second one works.

这里...

@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中执行此操作,

Here's how to do it in 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拖动到项目中(就像使用图片一样); 。确保他们有目标的成员

Simply drag "template.html" and "about.html" in to the project (just as you would with an image); ensure they have target membership.

推荐答案

您有一个错误<风格> block:它以< meta> 元素开始。这将抛出解析器;显然它认为直到第一个} 是坏的,需要被丢弃。

You have an error in the <style> block: it starts with a <meta> element. This will throw the parser off; apparently it thinks that everything up until the first } is bad and needs to be discarded.

解决方案: < style> 中的< meta>

这篇关于iOS UIWebView完全不能理解多个@ font-face?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆