谁能帮我在 webview 中添加 html 文件?我想用我的文本大小、字体和图像大小选项来呈现 html 数据。
我有这个 html 代码,当我将它添加到本地文件时它可以工作:
<style type="text/css">
img {
max-width: 348px !important;
}
body {
font-size: 15px !important;
font-size: HelveticaNeue !important;
}
</style>
我的问题是如何将此 html 代码添加到我使用 swift 从 URL 加载的每个文件中?
我想如果你想在文件的末尾添加这些html代码,没有问题。但据我所知,样式需要添加到head 中,所以我认为您必须分析html 字符串并找到插入样式的位置。问题似乎是字符串拼接。
let path = dir.stringByAppendingPathComponent(file);
//reading
let text = String(contentsOfFile: path, encoding: NSUTF8StringEncoding, error: nil)
// Here you should insert the <style> string in text
// Or you just add the <style> at the end of the text
//writing
text.writeToFile(path, atomically: false, encoding: NSUTF8StringEncoding, error: nil)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句