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