gpt4 book ai didi

html - 在 webview 中快速加载 html 文件,更改图像大小、字体和文本大小

转载 作者:行者123 更新时间:2023-11-28 06:13:45 25 4
gpt4 key购买 nike

谁能帮我在 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代码,没问题。但据我所知,style 需要在 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)

关于html - 在 webview 中快速加载 html 文件,更改图像大小、字体和文本大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45730273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com