Injecting a new stylesheet into a website via uiwebview using iOS8 Swift XCode 6

后端 未结 2 629
难免孤独
难免孤独 2020-12-21 14:57

I\'ve seen a few options on here using just Objective-C, but I\'m having trouble doing this with Swift iOS8 in XCode 6. I\'m using the uiwebview to load a website. For sake

2条回答
  •  难免孤独
    2020-12-21 15:25

    So, I think I found at least one way to accomplish appending styles to the webpage being loaded using Swift:

      var loadStyles = "var script = 
      document.createElement('link');
      script.type = 'text/css';
      script.rel = 'stylesheet';
      script.href = 'http://fake-url/styles.css';
      document.getElementsByTagName('body')[0].appendChild(script);"
    
      website.stringByEvaluatingJavaScriptFromString(loadStyles)
    

提交回复
热议问题