2

I am trying to add a custom css file to a uiwebview to put some elements in display:none, but after a lot of googling I cannot find a way to do it. It seems that I should inject it via javascript, but I don't really see how. Anyone having done that before?

Max
  • 5,380
  • 6
  • 42
  • 66
Kalianey
  • 2,738
  • 6
  • 25
  • 43

1 Answers1

0

you can do something like below, when you load your html file you can add the CSS file along in your project and load the html in webview, please also refer :- link

import UIKit


class ViewController: UIViewController {
@IBOutlet weak var webView: UIWebView!

    override func viewDidLoad() {
        // Do any additional setup after loading the view, typically from a nib.
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let localfilePath = NSBundle.mainBundle().URLForResource("test", withExtension: "html");
        let myRequest = NSURLRequest(URL: localfilePath!);
        webView.loadRequest(myRequest);
        //or use as below 
        let myHTMLString:String! = "<h1>Hello Pizza!</h1>"
        webView.loadHTMLString(myHTMLString, baseURL: nil)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }



}
Max
  • 5,380
  • 6
  • 42
  • 66
  • I'm using an external url which doesn't belong to me, where would the css be added in this case? – Kalianey Jul 16 '15 at 10:31
  • If your using a external url the css can only come from the external url which can be embedded on the server hosting that html file, you cannot modifiy a css of external links if you dont have control. – Max Jul 16 '15 at 10:33