在UIWebView中使用HTML和本地圖像我有一個UIWebView在我的應(yīng)用程序,我想用來顯示一個圖像,將鏈接到另一個網(wǎng)址。我在用<img src="image.jpg" /> to load the image.問題是圖像沒有加載。即使它作為資源添加到我的項(xiàng)目中并被復(fù)制到包中,也是找不到的。我嘗試使用NSBundle獲取圖像的完整路徑,并且使用它,但它仍然沒有顯示在Web視圖中。有什么想法嗎?
3 回答

人到中年有點(diǎn)甜
TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超7個贊
[webView loadHTMLString:htmlString baseURL:[[NSBundle mainBundle] bundleURL]];

30秒到達(dá)戰(zhàn)場
TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超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 關(guān)注
- 378 瀏覽
添加回答
舉報(bào)
0/150
提交
取消