Getting started with SDWebImage and getting started with sdwebimage

Source: Internet
Author: User

Getting started with SDWebImage and getting started with sdwebimage

 

Why use it?

(Original address: http://blog.csdn.net/niu_gao)

SDWebImage is a library for downloading images from a website. It extends the UIImageView class. UIImageView can directly download images from the website, but it does not consider caching the images. As a result, as long as the images are displayed, the network is accessible. SDWebImage solves this problem (of course, more than this function ).

Download location

Https://github.com/rs/SDWebImage

Compile

After the download, open the project and compile it.

Used by other projects

There are multiple methods to use in other projects. The simplest is to add the class and project references to other projects.

 

The procedure is as follows:

L in other projects, click the project name to bring up the menu.

L select Add files to "XXX ".

L select the project file of SDWebImage and select Copy items if needed.

Click Add.

 

Compilation. Because the source code of a library is missing, this library is called libwebp. Location: https://github.com/webmproject/libwebp.

Please download version 0.4.3. Otherwise, the compilation may fail. I am talking about the fact that later versions are needed in the last few months.

 

Copy the src directory of libwebp to Vendors/libwebp in SDWebImage. Recompile and pass.

 

However, your project will crash (provided that the SDWebImage function is used in your project ). You also need to add the link option:-ObjC.

 

If an error persists, you must add a reference to ImageIO. framework in "BuildPhases.

 

Sample Code:

# Import <SDWebImage/UIImageView + WebCache. h>...

-(UITableViewCell *) tableView :( UITableView *) tableView

CellForRowAtIndexPath :( NSIndexPath *) indexPath

{

StaticNSString * MyIdentifier = @ "MyIdentifier ";

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: MyIdentifier];

If (cell = nil ){

Cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault

ReuseIdentifier: MyIdentifier] autorelease];

}

// We use sd_setImageWithURL: To load web Images

[Cell. imageViewsd_setImageWithURL: [NSURL

URLWithString: @ "http://www.domain.com/path/to/image.jpg"]

PlaceholderImage: [UIImage imageNamed: @ "placeholder.png"];

Cell. textLabel. text = @ "My Text ";

Return cell;

}

 

(Original address: http://blog.csdn.net/niu_gao)


Use block

// We use sd_setImageWithURL: To load web Images
[cell.imageView sd_setImageWithURL:
        [NSURLURLWithString:@"http://www.domain.com/path/to/image.jpg"]
         placeholderImage:[UIImage imageNamed:@"placeholder.png"]        
        completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
               ... completion code here ...
        }
];

 

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.