Bro Bro - 7 months ago 92
Swift Question

Swift load html file in webview, change image size, font and text size

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;

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

Answer Source

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);

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

text.writeToFile(path, atomically: false, encoding: NSUTF8StringEncoding, error: nil)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download