题
我要显示在网页视图的局部图像,怎么办?某人有一个简单的演示?非常感谢!!!
解决方案
做的最好的办法是设置到基本URL分发包路径。然后从那里你可以从你的包调用图像,像这样:
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSURL *bundleBaseURL = [NSURL fileURLWithPath: bundlePath];
[webView loadHTMLString:htmlContent baseURL: bundleBaseURL];
在HTML图像可以然后直接调用本地图像。
<img src="yourImageFromTheMainBundle.jpg" />
同样可以用来调用CSS文件或JS甚至文件,因为看起来基本URL主Bunble内部。
如果它不是在你的主包,你所要做的就是改变以基本URL:在图象所在的路径。
其他提示
NSURL *imageURL = [NSURL fileURLWithPath:localImagePath];
NSURLRequest *request = [NSURLRequest requestWithURL:imageURL];
[[webView mainFrame] loadRequest:request];
不隶属于 StackOverflow