2015-05-16 24 views
0

我正在開發一個iOS新聞應用程序,它從url(JSON)獲取其內容。iOS:HTMLReader可以加載嵌入的圖像嗎?

在文章的詳細信息視圖控制器我犯了一個標籤,以顯示說明,假設我有以下字符串,應用程序會從JSON對象獲得(格式的URL):

"bla bla bla <div>another bla bla bla</div><img src="some_image_src" /> 
bla bla blabla <strong>bla</strong>" 

我使用HTMLReader刪除html標籤,除了字符串中的圖像,一切看起來都很棒,我如何顯示嵌入的圖像?

在此先感謝。

注: HTMLReader的文檔很短,他們沒有與你的網址說任何有關圖像標籤

回答

0

下載圖像數據,並使用NSMutableAttributedString:

NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil]; 
attachment.image = [UIImage imageNamed:@"whatever"]; 
NSAttributedString *attributedString = [NSAttributedString attributedStringWithAttachment:attachment]; 
yourTextView.attributedText = attributedString; 
+0

什麼,如果有一個以上圖像在html字符串中?以及如何將圖像放置在適當的位置?請詳細說明一下 – ANA

+0

[這裏](http:// localhost/radio-ana/api/article/205926093539783)是JSON數據的url,請查看json節點中的描述字符串,那就是我正在說的那個關於。 – ANA

相關問題