title: SWIFT - Loading local CSS file
body: <p>I am trying to add some local css to my webview but it seems that I have a problem with the css file in my app :</p>
  
  <p><a href="https://i.stack.imgur.com/Jrvqq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Jrvqq.png" alt="enter image description here"></a> </p>
  
  <p>Nothing happens when I try to load the css from the local css file but when I replace '%@' by a online css file it works fine.</p>
  
  <p>Thank you for your help.</p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController, UIWebViewDelegate {
  
      @IBOutlet weak var webview: UIWebView!
      override func viewDidLoad() {
          super.viewDidLoad()
          webview.delegate = self
  
          let html: String! = "&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;div id=\"postcontent\"&gt;&lt;h1&gt;Hello&lt;/h1&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;"
  
          webview.loadHTMLString(html, baseURL: nil)
      }
  
      func webViewDidFinishLoad(_ webView: UIWebView){
          let path = Bundle.main.path(forResource: "styles", ofType: "css")
  
          let javaScriptStr: NSString = "var link = document.createElement('link'); link.href = '%@'; link.rel = 'stylesheet'; document.head.appendChild(link)"
          let javaScripthPath = NSString(format: javaScriptStr, path!)
          webview.stringByEvaluatingJavaScript(from: javaScripthPath as String)
          print(javaScripthPath)
      }
  }
  </code></pre>