1

我需要在我的 Swift 应用程序中创建一个阅读器功能。我将收到这样的 HTML 文本(带有 json 请求):

<h5 align="LEFT" class="western" style="font-weight: normal;"> </h5>
<font size="3"><h5 align="LEFT" class="western" style="font-weight: normal;">
Albert Einstein publie en 1905, une nouvelle théorie connue sous le nom de relativité restreinte. </h5>
<h5 align="LEFT" class="western" style="font-weight: normal;"></h5>
<h5 align="LEFT" style="font-weight: normal;"><font color="#339933">►&lt;/font>
<font size="3">Postulat 1&nbsp;:</font>
</h5><h5 align="LEFT" class="western" style="font-weight: normal;">
</h5>

我想以具有所有属性的可读文本显示它,我不想丢失样式,因为我可以使用 HTMLReader。

你知道用 Swift 制作它的方法吗?

4

1 回答 1

0

这些是在 html 文件中定义的,然后必须使用 webview:

objweb.delegate = self
        var path = NSBundle.mainBundle().bundlePath

        var baseUrl  = NSURL.fileURLWithPath("\(path)")

        let bundle = NSBundle.mainBundle()
        let pathhtml = bundle.pathForResource("Armory", ofType: "html")
        let content = NSString.stringWithContentsOfFile(pathhtml) as String

        objweb.loadHTMLString(content, baseURL: baseUrl)
        self.view.addSubview(objweb)
于 2014-09-05T13:15:23.363 回答