Sdwebimage, some methods for loading images by third parties asynchronously

Source: Internet
Author: User

Sdwebimage, some methods for loading images by third parties asynchronously

1. First add third-party files (sdwebimage) to the project

2. Modify the Arc

          

3. Add a ImageView to the Viewcontrol to add a tap tap gesture to display the downloaded image

A. sd_setimagewithurl

Introducing Header Files

#import "uiimageview+webcache.h"

-(Ibaction) Tap: (UITapGestureRecognizer *) Sender {    NSLog (@ "%s", __ function__);     // loading pictures asynchronously    sd_setimagewithurl: [nsurl urlwithstring:@ "http://img3.douban.com/view/photo/photo/ Public/p1910869260.jpg"] placeholderimage:nil options:0];
}

B. Sdwebimagemanager

Introducing Header Files

#import "SDWebImageManager.h"

-(Ibaction) Tap: (UITapGestureRecognizer *) Sender {NSLog (@"%s", __function__); //Loading Pictures asynchronously    Sdwebimagemanager*manager =[Sdwebimagemanager Sharedmanager]; [Manager Downloadimagewithurl: [Nsurl urlwithstring:@"http://img3.douban.com/view/photo/photo/public/p2151245053.jpg"] Options:0progress:^(Nsinteger receivedsize, Nsinteger expectedsize) {} Completed:^ (UIImage *image, Nserror *error, Sdimagecachetype CacheType, BOOL finished, Nsurl *ImageURL) {        if(finished) {Self.imageView.image=image; }    }];}

c. sdwebimagedownloader Standalone use of asynchronous picture download

Introducing Header Files

#import "SDWebImageDownloader.h"

    Sdwebimagedownloader  *    Downloader = [Sdwebimagedownloader Shareddownloader]; [Downloader Downloadimagewithurl : [nsurl urlwithstring:  @ " http://img4.douban.com/view/photo/photo/public/p1940511226.jpg " Span style= "color: #800000;" > "] options:0  progress:^ (Nsinteger Receivedsize, Nsinteger expectedsize) {} Completed:  ^ (UIImage *image, NSData *data, Nserror *error, BOOL finished) { if   (finished) {        Self.imageView.image  = image; }    }];

d. Sdimagecache

Cache Pictures in Key value to mark the picture Extract Pictures The next time you want to use the image can be quickly extracted

Introducing Header Files

#import "uiimageview+webcache.h"

-(Ibaction) Tap: (UITapGestureRecognizer *) Sender {NSLog (@"%s", __function__); //Sdimagecache Single Case Method[[SdimagecacheSharedimagecache] Storeimage:[uiimage imagewithdata:[nsdata datawithcontentsofurl:[nsurl urlwithstring:@"http://img3.doubanio.com/view/photo/photo/public/p522751329.jpg"]] Forkey:@"MySpace"]; //Querydiskcacheforkey, looking for cached pictures by key value[[Sdimagecache Sharedimagecache]Querydiskcacheforkey:@"MySpace"done:^ (UIImage *image, Sdimagecachetype cachetype) {Self.imageView.image=image; }];}you don't need to download the image again, you can extract it directly from the cache.-(Ibaction) Other: (UITapGestureRecognizer *) Sender {NSLog (@" Other"); [[Sdimagecache Sharedimagecache] querydiskcacheforkey:@"MySpace"done:^ (UIImage *image, Sdimagecachetype cachetype) {Self.otherImage.image=image; }];}

Click ImageView to cache the image cache with the "MySpace" flag and display it, then click on another view to extract the image from the cache with the "MySpace" logo, without having to download it again to quickly show it.

Sdwebimage, some methods for loading images by third parties asynchronously

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.