【发布时间】:2014-09-19 08:27:09
【问题描述】:
我已经在我的 Xcode 应用程序包中添加了我的 Html、CSS 和图像文件。
在我的项目中,我像这样在 UIWebView 中加载了 Html 内容,
NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"myFile" ofType:@"html" inDirectory:nil];
NSString *htmlString = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
NSURL *Url = [NSURL fileURLWithPath:htmlString];
[self.webView loadHTMLString:htmlString baseURL:Url];
Html 文件已加载,但缺少 CSS 和图像。
在我的 Html 文件中添加 CSS 和图片如下,
<link href="/css/myCss.css" type="text/css" rel="stylesheet"/>
<img class"icon" alt="" src="/img/icon.png" />
需要帮助来解决这个问题。
【问题讨论】:
-
尝试在地址中的第一个“/”之前添加两个点,例如。 "../css/myCss.css" .
-
@AbhinavGauniyal:刚试过。但不工作
-
删除路径中的文件夹是否有效?这样 /css/myCss.css 就变成了 myCss.css 并且 /img/icon.png 变成了 icon.png。我相信这就是我不久前让它在我的应用程序中工作的方式,尽管这些文件位于文件夹和组中。
-
我也试过了,结果一样
-
哦,抱歉,刚刚检查了代码,我正在考虑的应用程序甚至没有使用 WebView :/
标签: html css iphone xcode uiwebview