亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在UIWebView中使用HTML和本地圖像

在UIWebView中使用HTML和本地圖像

iOS
回首憶惘然 2019-07-26 15:14:41
在UIWebView中使用HTML和本地圖像我有一個UIWebView在我的應用程序,我想用來顯示一個圖像,將鏈接到另一個網址。我在用<img src="image.jpg" /> to load the image.問題是圖像沒有加載。即使它作為資源添加到我的項目中并被復制到包中,也是找不到的。我嘗試使用NSBundle獲取圖像的完整路徑,并且使用它,但它仍然沒有顯示在Web視圖中。有什么想法嗎?
查看完整描述

3 回答

?
人到中年有點甜

TA貢獻1895條經驗 獲得超7個贊

用這個:

[webView loadHTMLString:htmlString baseURL:[[NSBundle mainBundle] bundleURL]];


查看完整回答
反對 回復 2019-07-27
?
30秒到達戰場

TA貢獻1828條經驗 獲得超6個贊

我也遇到了這個問題。在我的例子中,我處理的是一些沒有本地化的圖像,還有一些是多種語言的圖像?;綰RL沒有為我獲取本地化文件夾中的圖像。我通過以下操作解決了這個問題:

// 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];

然后,在加載內容時,在UIWebView HTML代碼中使用imgHTMLTag。

我希望這對任何遇到同樣問題的人都有幫助。




查看完整回答
反對 回復 2019-07-27
  • 3 回答
  • 0 關注
  • 384 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號