Download images from the server side of the project these are almost essential and simple to use, just introduce the Sdwebimage file
////VIEWCONTROLLER.M//Sdwebimagedemo////Created by City--online on 15/6/15.//Copyright (c) 2015 City--online. All rights reserved.//#import "ViewController.h"#import "uiimageview+webcache.h"@interfaceViewcontroller () @property (nonatomic,strong) Uiimageview*ImgView1, @property (nonatomic,strong) Uiimageview*ImgView2;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; UIButton*claerbtn=[UIButton Buttonwithtype:uibuttontypesystem]; [Claerbtn settitle:@"Clear Cache"Forstate:uicontrolstatenormal]; Claerbtn.frame=cgrectmake ( -,Ten, -, -); [Claerbtn addtarget:self Action: @selector (Btnclick:) forcontrolevents:uicontroleventtouchupinside]; Claerbtn.tag=10001; [Self.view ADDSUBVIEW:CLAERBTN]; UIButton*loadbtn=[UIButton Buttonwithtype:uibuttontypesystem]; [Loadbtn settitle:@"Loading"Forstate:uicontrolstatenormal]; Loadbtn.frame=cgrectmake ( the,Ten, -, -); [Loadbtn addtarget:self Action: @selector (Btnclick:) forcontrolevents:uicontroleventtouchupinside]; Loadbtn.tag=10002; [Self.view ADDSUBVIEW:LOADBTN]; _imgview1=[[uiimageview Alloc]initwithframe:cgrectmake ( -, -, -, -)]; _imgview1.backgroundcolor=[Uicolor Graycolor]; [Self.view Addsubview:_imgview1]; _imgview2=[[uiimageview Alloc]initwithframe:cgrectmake ( -,380, -, -)]; _imgview2.backgroundcolor=[Uicolor Graycolor]; [Self.view Addsubview:_imgview2]; }-(void) Btnclick: (ID) sender{UIButton*btn= (UIButton *) sender; if(btn.tag==10001) {[[Sdimagecache Sharedimagecache] cleardisk]; [[Sdimagecache Sharedimagecache] clearmemory]; } Else if(btn.tag==10002) {Nsurl*imgpath1=[nsurl urlwithstring:@"http://s15.sinaimg.cn/middle/9914f9fdhbc6170891ebe&690"]; Nsurl*imgpath2=[nsurl urlwithstring:@"http://s14.sinaimg.cn/middle/9914f9fdhbc611c219f3d&690"]; //Basic Use Method//[_imgview1 sd_setimagewithurl:imgpath1];// // //Block//[_imgview2 sd_setimagewithurl:imgpath2 completed:^ (UIImage *image, Nserror *error, Sdimagecachetype CacheType, Nsurl *imageurl) {//NSLog (@ "Here to do something after the picture is loaded");// }]; //pre-set a picture//[_imgview1 sd_setimagewithurl:imgpath1 placeholderimage:[uiimage imagenamed:@ "default.jpg"];// // //block pre-set a picture//[_imgview2 sd_setimagewithurl:imgpath2 placeholderimage:[uiimage imagenamed:@ "default.jpg"] completed:^ (UIImag E *image, Nserror *error, Sdimagecachetype cachetype, Nsurl *imageurl) {//NSLog (@ "Here to do something after the picture is loaded");// }];//[_imgview1 sd_setimagewithurl:imgpath1 placeholderimage:[uiimage imagenamed:@"default.jpg"] options:sdwebimagecachememoryonly]; Sdwebimagemanager*manager=[Sdwebimagemanager Sharedmanager]; [Manager downloadimagewithurl:imgpath2 options:sdwebimageretryfailed Progress:^(Nsinteger receivedsize, Nsinteger expectedsize) {NSLog (@"%f", receivedsize/(float) expectedsize); } Completed:^ (UIImage *image, Nserror *error, Sdimagecachetype CacheType, BOOL finished, Nsurl *ImageURL) {NSLog (@"Download Complete"); _imgview2.image=image; }];// // /* // //Retry after failure//sdwebimageretryfailed = 1 << 0,// // //download begins during UI interaction, resulting in delayed downloads such as Uiscrollview deceleration. //sdwebimagelowpriority = 1 << 1,// // //Memory Cache only//sdwebimagecachememoryonly = 1 << 2,// // //This flag can be incrementally downloaded, and the displayed image is progressively downloaded in//sdwebimageprogressivedownload = 1 << 3,// // //Refresh Cache//sdwebimagerefreshcached = 1 << 4,// // //Background Download//sdwebimagecontinueinbackground = 1 << 5,// // //nsmutableurlrequest.httpshouldhandlecookies = YES; // //sdwebimagehandlecookies = 1 << 6,// // //allow an invalid SSL certificate to be used// //sdwebimageallowinvalidsslcertificates = 1 << 7,// // //Priority Download//sdwebimagehighpriority = 1 << 8,// // //Delay Placeholder//Sdwebimagedelayplaceholder = 1 << 9,// // //change the animated image//sdwebimagetransformanimatedimage = 1 <<,// */ }}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}@end
iOS third party sdwebimage