Async image downloader

前端 未结 5 1181
北海茫月
北海茫月 2021-02-01 11:37

I have write a little class to perform the download of the images by using an NSURLConnection. The idea it\'s to delegate the download to this class to avoid to block the execu

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-01 12:07

    Use SDWebImage simply. I'm also using that one. Loading images smoothy. Am using below code to show the image from URL

    [myImageView setImageWithURL:[NSURL URLWithString:@"www.sample.com/image.png"] placeholderImage:[UIImage imageNamed:@"lod.png"] 
    success:^(UIImage *image, BOOL cached)
    {
        productImageDetails.image = image;
    } 
    failure:^(NSError *error) {
        productImageDetails.image =[UIImage imageNamed:@"no_image.jpg"];
    }];
    

    Success part will display the image from webService. And, if there's any image failed to load or anyother failure issue you can load your own image there simply. There are more functionalities with that example. You can just refer it.

提交回复
热议问题