iOS Development-third party sdwebimage download the use of network pictures

Source: Internet
Author: User

Request pictures from the network, without using a third party, the download will be very slow, and plug the thread, but also to handle multi-threaded problems, the effect is very not obvious, using the Sdwebimage third-party class library, download the picture becomes much easier.

sdwebimage This class library provides a uiimageview category to support the loading of remote pictures from the network. Features such as cache management, asynchronous download, same URL download count control and optimization

Installing Sdwebimage with Cocoapods

Put pod ' sdwebimage ' in Profile, ' ~> 3.7.3 ' save, pod Isntall installation, can be used after completion

Import

#import <SDWebImage/UIImageView+WebCache.h>

The following code is to load a picture using a third-party sdwebimage

1-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath2 {3NSString *id =@"hh";4Mytableviewcell *cell =[TableView Dequeuereusablecellwithidentifier:id];5     if(!cell) {6Cell =[[Mytableviewcell Alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:id];7     }8    9 Ten     //put the requested picture address into a model and now take out the model OneNewmodel *goosmodel =Arry[indexpath.row]; ANewmodel *model =Arry[indexpath.row]; -    //Convert to Nsurl -Nsurl *urls =[Nsurl Urlwithstring:model. Images]; the             //processing pictures with third parties -            [cell.baiamge sd_setimagewithpreviouscachedimagewithurl:urls andplaceholderimage:[uiimage imageNamed:@ "Picture Plus Download "] options:sdwebimagecachememoryonly progress:^ (Nsinteger receivedsize, Nsinteger expectedsize) {17//here is                 Download progress of the picture completed:^ (UIImage *image, Nserror *error, Sdimagecachetype cachetype, Nsurl *imageurl) {19 Here you can do the pictures after downloading the things to do [];

One, options all option

1. Details

* Default URL, when a URL download fails, so the library will not be downloaded again.
* This flag disables this blacklist.
* /
sdwebimageretryfailed = 1<<0
*
* Images are started in the interaction of the user interface, this flag disables this function
* Causes delay download Uiscrollview spin down.
* /
sdwebimagelowpriority = 1<<1;
*
This flag is cached on disk (this is not recommended for download to memory)
* /
sdwebimagecachememoryonly = 1<<2
*
* can be progressively downloaded, the displayed image is progressively in the download. Show only one full download of the image, the image slowly showing the kind of---can not set the default image
* /
sdwebimageprogressivedownload = 1<<3
*
* Even the image aspect of the cache, and the HTTP response cache refresh control If the image is needed from a remote location.
* The disk cache will be processed by Nsurlcache instead of sdwebimage, resulting in a slight performance degradation.

* this option helps to deal with changing images in the same request URL, such as a profile picture of the Facebook API.
* Use this flag only if you cannot get your URL corrupted with embedded static cache parameters.
*/

*
* on iOS 4 +, continue to download the app's image to go to the background. This is the implementation of part of the study by the roaming system
* the extra background to make the request complete. If the background work exits the program operation will be canceled.
*/

*


//nsmutableurlrequest.httpshouldhandlecookies  = YES;
*/
Sdwebimagehandlecookies = 1<<6
*
* Enable SSL for untrusted certificates.
* Useful for testing purposes. A warning is used in production.
*/
Sdwebimageallowinvalidsslcertificates = 1<<7
*
* By default, the order in which pictures are loaded is queued. This flag moves them immediately before loading the queue, rather than waiting to load the current queue (which may take some time).
*/
Sdwebimagehighpriority = 1<<8
*
* default, the image is loaded in the image placeholder is loaded. This flag is to load the delay. The
* Placeholder image is not completed until the image is loaded. This setting default picture doesn't work.
*/
Sdwebimagedelayplaceholder = 1<<9
*
We don't usually call transformdownloadedimage representation in animated images
* Because most of the conversion code will corrupt it
* Use this flag to change them
*/
Sdwebimagetransformanimatedimage = 1<<10
*
* is the default, the image is added to the ImageView after downloading. But in some cases, we would like
* to have hands in the background image (it is associated with filtering or adding, applying a crossfade animation for example)
* Use this flag if you want to manually set the image when successfully completed
*/
Sdwebimageavoidautosetimage = 1<<11

Generally speaking, besides sdwebimagerefreshcached and sdwebimagecachememoryonly, others are often used! It's not much different, see the specific project needs .

2.简单

   //失败后URL是黑名单库不会继续重试       SDWebImageRetryFailed = 1 << 0,             //图像是在用户界面的相互作用开始,这个标志禁用这个功能
       *导致延迟下载uiscrollview降速。
      SDWebImageLowPriority = 1 << 1,              //只进行内存缓存       SDWebImageCacheMemoryOnly = 1 << 2,              //这个标志可以渐进式下载,显示的图像是逐步在下载       SDWebImageProgressiveDownload = 1 << 3,              //刷新缓存       SDWebImageRefreshCached = 1 << 4,              //后台下载       SDWebImageContinueInBackground = 1 << 5,              //NSMutableURLRequest.HTTPShouldHandleCookies = YES;              SDWebImageHandleCookies = 1 << 6,              //允许使用无效的SSL证书       //SDWebImageAllowInvalidSSLCertificates = 1 << 7,              //优先下载       SDWebImageHighPriority = 1 << 8,              //延迟占位符       SDWebImageDelayPlaceholder = 1 << 9,              //改变动画形象       SDWebImageTransformAnimatedImage = 1 << 10,

iOS Development-third party sdwebimage download the use of network pictures

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.