在UIWebView中使用HTML和本地图像我有一个UIWebView在我的应用程序,我想用来显示一个图像,将链接到另一个网址。我在用<img src="image.jpg" /> to load the image.问题是图像没有加载。即使它作为资源添加到我的项目中并被复制到包中,也是找不到的。我尝试使用NSBundle获取图像的完整路径,并且使用它,但它仍然没有显示在Web视图中。有什么想法吗?
3 回答
人到中年有点甜
TA贡献1895条经验 获得超7个赞
[webView loadHTMLString:htmlString baseURL:[[NSBundle mainBundle] bundleURL]];
30秒到达战场
TA贡献1828条经验 获得超6个赞
// make sure you have the image name and extension (for demo purposes, I'm using "myImage" and "png" for the file "myImage.png", which may or may not be localized)NSString *imageFileName = @"myImage";NSString *imageFileExtension = @"png";// load the path of the image in the main bundle (this gets the full local path to the image you need, including if it is localized and if you have a @2x version)NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageFileName ofType:imageFileExtension];// generate the html tag for the image (don't forget to use file:// for local paths)NSString *imgHTMLTag = [NSString stringWithFormat:@"<img src=\"file://%@\" />", imagePath];
- 3 回答
- 0 关注
- 352 浏览
添加回答
举报
0/150
提交
取消