1

Can anyone help me with add html file in webview? I want to present html data with my options of text size, font and image size.

I have this html code, it works when I add it in local file :

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

My question is how add this html code to each file I load from URL with swift?

Bro
  • 35
  • 5

1 Answers1

1

I think if you want to add these html code at the end of a file, it's no problem. But as I know, the style needs to add in head, so I think you must Analysis the html string and find where to insert the style. The the problem is seem to be a string stitching.

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)
pluto
  • 516
  • 6
  • 9