Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在webview中快速加载html文件,更改图像大小、字体和文本大小_Html_Ios_Swift_Webview - Fatal编程技术网

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

在webview中快速加载html文件,更改图像大小、字体和文本大小,html,ios,swift,webview,Html,Ios,Swift,Webview,有人能帮我在webview中添加html文件吗?我想用我的文本大小、字体和图像大小选项呈现html数据 我有这段html代码,当我将其添加到本地文件中时,它可以工作: <style type="text/css"> img { max-width: 348px !important; } body { font-size: 15px !important; font-size: HelveticaNeue !important; } &

有人能帮我在webview中添加html文件吗?我想用我的文本大小、字体和图像大小选项呈现html数据

我有这段html代码,当我将其添加到本地文件中时,它可以工作:

<style type="text/css">
    img {
        max-width: 348px !important;
    }
body {
    font-size: 15px !important;
    font-size: HelveticaNeue !important;
}
</style>

img{
最大宽度:348px!重要;
}
身体{
字体大小:15px!重要;
字体大小:HelveticaNeue!重要;
}

我的问题是如何将这个html代码添加到我用swift从URL加载的每个文件中

我认为,如果您想在文件末尾添加这些html代码,这没有问题。但正如我所知,样式需要添加标题,因此我认为您必须分析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)
let path=dir.stringByAppendingPathComponent(文件);
//阅读
let text=String(contentsOfFile:path,编码:NSUTF8StringEncoding,错误:nil)
//在这里,您应该在文本中插入字符串
//或者您只需在文本末尾添加
//书写
writeToFile(路径,原子性:false,编码:NSUTF8StringEncoding,错误:nil)

您必须按请求加载。看看这个链接,谢谢Gagan!