2012-06-06 38 views

回答

0

要載入本地文件中的WebView執行以下操作

NSString *imagePath = [[NSBundle mainBundle] resourcePath]; 
imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"]; 
imagePath = [imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"]; 

NSString *HTMLData = @" 
<img src="YOUR_IMAGE.jpg" alt="" width="100" height="100" />"; 

[webView loadHTMLString:HTMLData baseURL:[NSURL URLWithString: [NSString stringWithFormat:@"file:/%@//",imagePath]]]; 

這應該加載YOUR_IMAGE.jpg的UIWebView的 內閱讀更多從 http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/

+0

謝謝,但這並不完全是我想要完成的,我還不夠具體。我想在本地HTML文件中顯示來自NSDocumentDirectory的圖像,換句話說 - 將src =「」設置爲用戶文檔目錄中文件的路徑。這可以做到嗎? – user1433391

+0

@ user1433391好吧,我明白了,請檢查更新的答案 –

+0

有一個叫'+ [NSURL fileURLWithPath:]'這個瘋狂的事情......「 –