作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试在我的 WebView 中加载本地 HTML 页面。它加载但未加载图像。
我的文件结构如下:
index.html 中的图片路径
<div class = "logo mt10 text-center"> <img src="images/logo.png" alt="Logo Goes Here"> </div>
在 Web View 中加载 HTML 页面
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[web loadHTMLString:htmlString baseURL:baseURL];
帮我解决这个问题
最佳答案
嘿,你可以使用以下方式来做到这一点:
通过使用您的文件或文件夹的相对路径,您的本地 html 与相对引用将为您工作。
按照以下步骤操作:
使用以下代码使用相对路径加载文件。
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"www"]];
[webview loadRequest:[NSURLRequest requestWithURL:url]];
您所有的相关链接(如 img/.gif、js/.js)都将得到解析。
然后您可以像这样引用您的图像:
<img src="myimage.png">
我认为你的问题只是因为相对路径。请按照上述步骤操作。您将在 webview 上看到加载的图像。
关于javascript - 在 iPhone 中加载 HTML 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24306106/
我正在开发一个需要能够平均三个数字的 Facebook 应用程序。但是,它总是返回 0 作为答案。这是我的代码: $y = 100; $n = 250; $m = 300; $number = ($y
我只是无法弄清楚这一点,也找不到任何对我来说有意义的类似问题。我的问题:我从数据库中提取记录,并在我的网页上以每个面板 12 条的倍数显示它们。因此,我需要知道有多少个面板可以使用 JavaScrip
我是一名优秀的程序员,十分优秀!