• <i id='7RVLr'><tr id='7RVLr'><dt id='7RVLr'><q id='7RVLr'><span id='7RVLr'><b id='7RVLr'><form id='7RVLr'><ins id='7RVLr'></ins><ul id='7RVLr'></ul><sub id='7RVLr'></sub></form><legend id='7RVLr'></legend><bdo id='7RVLr'><pre id='7RVLr'><center id='7RVLr'></center></pre></bdo></b><th id='7RVLr'></th></span></q></dt></tr></i><div id='7RVLr'><tfoot id='7RVLr'></tfoot><dl id='7RVLr'><fieldset id='7RVLr'></fieldset></dl></div>
    <legend id='7RVLr'><style id='7RVLr'><dir id='7RVLr'><q id='7RVLr'></q></dir></style></legend>
    <tfoot id='7RVLr'></tfoot>
    • <bdo id='7RVLr'></bdo><ul id='7RVLr'></ul>

      <small id='7RVLr'></small><noframes id='7RVLr'>

      1. 使用 iOS8 Swift XCode 6 通过 uiwebview 将新样式表注入网站

        时间:2023-10-21

          • <bdo id='yz5HJ'></bdo><ul id='yz5HJ'></ul>

              <legend id='yz5HJ'><style id='yz5HJ'><dir id='yz5HJ'><q id='yz5HJ'></q></dir></style></legend>
              <i id='yz5HJ'><tr id='yz5HJ'><dt id='yz5HJ'><q id='yz5HJ'><span id='yz5HJ'><b id='yz5HJ'><form id='yz5HJ'><ins id='yz5HJ'></ins><ul id='yz5HJ'></ul><sub id='yz5HJ'></sub></form><legend id='yz5HJ'></legend><bdo id='yz5HJ'><pre id='yz5HJ'><center id='yz5HJ'></center></pre></bdo></b><th id='yz5HJ'></th></span></q></dt></tr></i><div id='yz5HJ'><tfoot id='yz5HJ'></tfoot><dl id='yz5HJ'><fieldset id='yz5HJ'></fieldset></dl></div>

                  <tbody id='yz5HJ'></tbody>
              1. <tfoot id='yz5HJ'></tfoot>
                • <small id='yz5HJ'></small><noframes id='yz5HJ'>

                  本文介绍了使用 iOS8 Swift XCode 6 通过 uiwebview 将新样式表注入网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在这里看到了一些仅使用 Objective-C 的选项,但我在 XCode 6 中使用 Swift iOS8 执行此操作时遇到了问题.我正在使用 uiwebview 加载网站.例如,假设它的 google.com.

                  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 of example, let's say its google.com.

                  @IBOutlet var website: UIWebView!
                  
                  var url = "http://www.google.com"
                  
                  func loadUrl() {
                      let requestURL = NSURL(string: url)
                      let request = NSURLRequest(URL: requestURL!)
                      website.loadRequest(request)
                  }
                  
                  override func viewDidLoad() {
                      super.viewDidLoad()
                      website.delegate = self
                      loadUrl()
                  }
                  
                  func webViewDidFinishLoad(website: UIWebView) {
                      var jsscript = "some script here"
                      website.stringByEvaluatingJavaScriptFromString(jsscript)
                  }
                  

                  使用 Swift,我如何将一个全新的样式表注入网站,以便我可以覆盖许多样式?

                  Using Swift, how would I inject a whole new stylesheet into the website so I can overwrite many of the styles?

                  另外,我希望新样式表存在于我的应用程序目录之一中.最好的目录在哪里?在支持文件?"下而且,我将如何在我的代码中调用该路径?

                  Also, I'd like the new stylesheet to exist in one of my app's directories. Where is the best directory for that to be? Under "Supporting files?" And, how would I call that path in my code?

                  如果在应用样式之前网站不加载也很好.

                  It would also be nice if the website wouldn't load until the styles had been applied.

                  推荐答案

                  所以,我想我至少找到了一种方法来完成将样式附加到使用 Swift 加载的网页:

                  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)
                  

                  这篇关于使用 iOS8 Swift XCode 6 通过 uiwebview 将新样式表注入网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:源代码和 DOM 有什么区别? 下一篇:使用保存在 iOS 应用程序的沙箱(文档目录)中的 .html、.js 文件,这样我也可以在离线模式下打开 html 文

                  相关文章

                  <i id='y81Jh'><tr id='y81Jh'><dt id='y81Jh'><q id='y81Jh'><span id='y81Jh'><b id='y81Jh'><form id='y81Jh'><ins id='y81Jh'></ins><ul id='y81Jh'></ul><sub id='y81Jh'></sub></form><legend id='y81Jh'></legend><bdo id='y81Jh'><pre id='y81Jh'><center id='y81Jh'></center></pre></bdo></b><th id='y81Jh'></th></span></q></dt></tr></i><div id='y81Jh'><tfoot id='y81Jh'></tfoot><dl id='y81Jh'><fieldset id='y81Jh'></fieldset></dl></div>

                  <small id='y81Jh'></small><noframes id='y81Jh'>

                • <tfoot id='y81Jh'></tfoot>
                    <bdo id='y81Jh'></bdo><ul id='y81Jh'></ul>

                    <legend id='y81Jh'><style id='y81Jh'><dir id='y81Jh'><q id='y81Jh'></q></dir></style></legend>