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

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

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

    1. <tfoot id='hFe1m'></tfoot>

      1. 如何在 Xcode 中向 UIWebView 添加外部样式表?

        时间:2023-10-22
          <bdo id='2i31S'></bdo><ul id='2i31S'></ul>

          <small id='2i31S'></small><noframes id='2i31S'>

                <legend id='2i31S'><style id='2i31S'><dir id='2i31S'><q id='2i31S'></q></dir></style></legend>

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

                <tfoot id='2i31S'></tfoot>
                    <tbody id='2i31S'></tbody>
                • 本文介绍了如何在 Xcode 中向 UIWebView 添加外部样式表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我查看了各种类似的问题和答案,但仍然无法解决这个问题,所以我添加了我自己的问题:

                  I have looked at various similar questions and answers and still cannot get this to work, so I'm adding my own question:

                  我正在玩 UIWebView.我可以使用内联 CSS 创建一个工作 html 页面.如果 CSS 在应用资源组的文件中,我无法弄清楚如何加载它.

                  I'm playing with UIWebView. I can create a working html page with inline CSS. I cannot figure out how to get the CSS to load if it is in a file in the app resources group.

                  我的代码是:

                  NSString *path = [[NSBundle mainBundle] pathForResource:@"webViewPage2" ofType:@"html"];
                      NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
                  
                      NSString *htmlString = [[NSString alloc] initWithData: 
                                                [readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
                  
                  
                      webView.opaque = NO;
                      webView.backgroundColor = [UIColor clearColor];
                      [self.webView loadHTMLString:htmlString baseURL:nil];
                      [htmlString release];
                  

                  我的 html 调用是这样的:

                  And my html call is this:

                  <html>
                  <head>
                  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
                  <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
                  <link rel="stylesheet" type="text/css" media="only screen and (max-device-width: 480px)" href="/greek123.css" />
                  </head>
                  
                  <body style="background-color: transparent;">
                  
                  <h2>Some Title</h2>
                  
                  
                  <p>We can put instructions here. Such as: 
                  "uh-oh You should not have pushed that button!"
                  </p>
                  
                  
                  </body>
                  
                  </html>
                  

                  如果有任何想法或解决方案,我将不胜感激.非常感谢!

                  I would appreciate any ideas or solutions. Many thanks!

                  推荐答案

                  将 UIWebView 的 baseURL 更改为 mainbundle 的 url.

                  change the baseURL of the UIWebView to the url of your mainbundle.

                  NSURL *mainBundleURL = [[NSBundle mainBundle] bundleURL];
                  [self.webView loadHTMLString:htmlString baseURL:mainBundleURL];
                  

                  斯威夫特 3:

                  webView.loadHTMLString(contentString, baseURL: Bundle.main.bundleURL)
                  

                  这篇关于如何在 Xcode 中向 UIWebView 添加外部样式表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:UIWebView 将 Objective C 暴露给 JavaScript 下一篇:将 UIWebView 渲染到 ImageContext

                  相关文章

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

                    1. <small id='kn2FK'></small><noframes id='kn2FK'>

                    2. <legend id='kn2FK'><style id='kn2FK'><dir id='kn2FK'><q id='kn2FK'></q></dir></style></legend>

                    3. <tfoot id='kn2FK'></tfoot>