• <small id='PI7CL'></small><noframes id='PI7CL'>

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

        在 uiwebview 中使用本地 html 从相对路径加载资源

        时间:2023-10-23

          <tbody id='60LpI'></tbody>

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

          <tfoot id='60LpI'></tfoot>
            <bdo id='60LpI'></bdo><ul id='60LpI'></ul>
            1. <legend id='60LpI'><style id='60LpI'><dir id='60LpI'><q id='60LpI'></q></dir></style></legend>

                <small id='60LpI'></small><noframes id='60LpI'>

                • 本文介绍了在 uiwebview 中使用本地 html 从相对路径加载资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个非常简单的 iOS 应用程序,带有一个加载一个非常简单的测试页面 (test.html) 的 uiwebview:

                  I have a very simple iOS app with a uiwebview loading a very simple test page (test.html):

                  <html>
                  <body>
                  <img src="img/myimage.png" />
                  </body>
                  </html>
                  

                  我将此 test.html 文件加载到我的网络视图中:

                  I load this test.html file into my web view:

                  NSURL *url = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"html"];
                  NSString *html = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
                  NSURL *baseUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
                  [webView loadHTMLString:html baseURL:baseUrl];
                  

                  如果我在没有相对路径的情况下引用图像并将引用的图像放在根路径下 Targets -> Copy Bundle Resources 在 XCode 下,这可以正常工作,但是我无法使用相对路径,如图所示我的 html 文件.必须有办法做到这一点,我有很多图像、css、javascript 文件要加载到 web 视图中,我不想将所有内容都放在根目录中,并且必须更改我的 web 中的所有引用应用程序.

                  This works fine if I reference the image without the relative path and put the referenced image in the root path under Targets -> Copy Bundle Resources within XCode, however I can't get it to work with the relative path as shown in my html file. There must be a way to do this, I have lots of images, css, javascript files that I want to load into the webview and I would like not to have to have everything in the root and have to change all the references in my web app.

                  推荐答案

                  这是如何加载/使用具有相对引用的本地 html.

                  This is how to load/use a local html with relative references.

                  1. 将资源拖到您的 xcode 项目中(我从 finder 窗口中拖了一个名为 www 的文件夹),您将获得两个选项为任何添加的文件夹创建组"和为任何添加的文件夹创建文件夹引用".
                  2. 选择创建文件夹引用.."选项.
                  3. 使用下面给出的代码.它应该像魅力一样发挥作用.

                  1. Drag the resource into your xcode project (I dragged a folder named www from my finder window), you will get two options "create groups for any added folders" and "create folders references for any added folders".
                  2. Select the "create folder references.." option.
                  3. Use the below given code. It should work like a charm.

                  NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"www"]];
                  [webview loadRequest:[NSURLRequest requestWithURL:url]];

                  现在您在 html 中的所有相关链接(如 img/.gif、js/.js)都应该得到解析.

                  Now all your relative links(like img/.gif, js/.js) in the html should get resolved.

                  斯威夫特 3

                      if let path = Bundle.main.path(forResource: "dados", ofType: "html", inDirectory: "root") {
                          webView.load( URLRequest(url: URL(fileURLWithPath: path)) )
                      }
                  

                  这篇关于在 uiwebview 中使用本地 html 从相对路径加载资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 iOS 4.2 中未正确绘制子类 UIAlertView 下一篇:UIWebView:当应用程序进入后台时,iOS 6 中的 HTML5 音频暂停

                  相关文章

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

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