Third-party framework-sdwebimage picture Processing framework

Source: Internet
Author: User

Sdwebimage Frame

Picture Processing Framework
Included features: Picture download, image caching, download progress monitoring, GIF processing, and more
The usage is extremely simple, the function is very powerful, greatly improved the network picture processing efficiency
More than 90% of iOS projects in the country have its shadow

Sdwebimage Common methods
-(void)Sd_setimagewithurl:(nsurl *)URL Placeholderimage:(UIImage *)placeholder;-(void)Sd_setimagewithurl:(nsurl *)URL Placeholderimage:(UIImage *)Placeholder options:(sdwebimageoptions)options;-(void)Sd_setimagewithurl:(nsurl *)URL Placeholderimage:(UIImage *)Placeholder Completed:(sdwebimagecompletionblock)completedblock;-(void)Sd_setimagewithurl:(nsurl *)URL Placeholderimage:(UIImage *)Placeholder options:(sdwebimageoptions)Options Progress:(sdwebimagedownloaderprogressblock)Progressblock Completed:(sdwebimagecompletionblock)Completedblock;
Sdwebimage Memory Processing

Memory processing: Called when the app receives a memory warning

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application{    SDWebImageManager *mgr = [SDWebImageManager sharedManager];    // 1.取消正在下载的操作    [mgr cancelAll];    // 2.清除内存缓存    [mgr.imageCache clearMemory];}
Sdwebimageoptions
//下载失败后,会自动重新下载//当正在进行UI交互时,自动暂停内部的一些下载操作//拥有上面2个功能
Sdwebimage Picture Caching Process Analysis

Sdwebimage is a very powerful framework for caching network pictures. The framework realizes the functions of asynchronously loading the network picture and automatically caching the picture data. With Uiimageview
Load the network picture as an example, the overall picture of the loading process to do a rough analysis. First use Sdwebimage to import first

#import "UIImageView+WebCache.h"文件

Set the picture address of the network picture to load the picture.
Project Address
Https://github.com/rs/SDWebImage

Picture Processing Framework Example
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com/image.jpg"];  [imageView sd_setImageWithURL:url];  
Sdwebimage instances

With blocks, you will be informed of the download progress, success or failure when completed:

 @interface appsviewcontroller ()/** * All application Data * /@property(nonatomic,Strong)Nsmutablearray*apps;@end @implementation appsviewcontroller #pragma mark-Lazy loading- (Nsmutablearray*) apps{if(!_apps) {//1. Load plist        NSString*file = [[NSBundleMainbundle] pathforresource:@"Apps"oftype:@"Plist"];Nsarray*dictarray = [NsarrayArraywithcontentsoffile:file];//2. Dictionary---model        Nsmutablearray*apparray = [NsmutablearrayArray]; for(nsdictionary*dict in Dictarray) {Hmapp *app = [Hmapp appwithdict:dict];        [Apparray Addobject:app]; }//3. Assigning Values         Self. Apps= Apparray;//_apps = Apparray;}return_apps;}#pragma mark-Initialize method- (void) viewdidload{[SuperViewdidload];} - (void) didreceivememorywarning{[SuperDidreceivememorywarning];}#pragma mark-table view data source- (Nsinteger) TableView: (UITableView*) TableView numberofrowsinsection: (Nsinteger) section{return  Self. Apps. Count;} - (UITableViewCell*) TableView: (UITableView*) TableView Cellforrowatindexpath: (Nsindexpath*) indexpath{Static NSString*id = @"App";UITableViewCell*cell = [TableView dequeuereusablecellwithidentifier:id];if(!cell) {cell = [[UITableViewCellAlloc] Initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:id]; }//Set basic informationCell. Textlabel. Text= App. Name; Cell. Detailtextlabel. Text= App. Download;//Download Images    Nsurl*url = [NsurlUrlwithstring:app. Icon];UIImage*placeholder = [UIImageimagenamed:@"Placeholder"]; [Cell. ImageViewSd_setimagewithurl:url Placeholderimage:placeholder]; [Cell. ImageViewSd_setimagewithurl:url Placeholderimage:placeholder completed:^ (UIImage*image,Nserror*error, Sdimagecachetype CacheType,Nsurl*imageurl) {NSLog(@"----Picture loaded---%@", image);    }]; Sdwebimageoptions options = sdwebimageretryfailed |    sdwebimagelowpriority; [Cell. ImageViewSd_setimagewithurl:url Placeholderimage:placeholder options:options progress:^ (NsintegerReceivedsize,NsintegerExpectedsize) {//This block may be called multiple times        NSLog(@"Download progress:%f", (Double) receivedsize/expectedsize); } completed:^ (UIImage*image,Nserror*error, Sdimagecachetype CacheType,Nsurl*imageurl) {NSLog(@"----Picture loaded---%@", image); }];returnCell;}@end

Memory Processing:

/** *  当app接收到内存警告 */- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application{    SDWebImageManager *mgr = [SDWebImageManager sharedManager];    // 1.取消正在下载的操作    [mgr cancelAll];    // 2.清除内存缓存    [mgr.imageCache clearMemory];}

Third-party framework-sdwebimage picture Processing framework

Related Article

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.