簡體   English   中英

如何從網上下載圖像並將其顯示在UIImageView中?

[英]How to download an image from the web and display it in an UIImageView?

如何從網上下載圖像並將其顯示在UIImageView中? 例如,我有一個網址,例如: http : //sstatic.net/so/apple-touch-icon.png

替代文字

我是否需要弄亂NSURLConnection之類的東西,還是有一個簡單的方法來獲取Web URL並自動下載圖像數據?

您可以使用NSDatadataWithContentsOfURL:類方法從服務器下載圖像數據,然后將其傳遞給UIImageimageWithData:類方法。

這是一個例子:

NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://sstatic.net/so/apple-touch-icon.png"]];

UIImage *downloadedImage = [UIImage imageWithData:imageData];

myImageView.image = downloadedImage;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM