Getting Started with Sdwebimage

Source: Internet
Author: User

Why do you use it?

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

Sdwebimage is a library that downloads pictures from a Web site, and it expands the Uiimageview class. Uiimageview could have downloaded the image directly from the website, but it did not consider caching the picture, causing the network to be accessed whenever the picture was displayed. And Sdwebimage solves the problem (of course, not just this one).

Download location

Https://github.com/rs/SDWebImage

Compile

After downloading, directly open the project to compile.

Used by other projects

There are several ways to use it in other projects, and the simplest is to add a reference to a class, project, to another project.

The steps are as follows:

L in other projects, the name of the project on the popup menu.

L Select Add files to "XXX".

L Select the Sdwebimage project file and select copy items if needed.

L DOT Add.

Compile, pass. Because of the lack of a library source code, this library is called LIBWEBP. Location: HTTPS://GITHUB.COM/WEBMPROJECT/LIBWEBP.

Please download version 0.4.3, otherwise the compilation will not pass. What I'm saying is now, in a few months, it's going to be a higher version.

Copy the SRC directory of LIBWEBP to the VENDORS/LIBWEBP in Sdwebimage. Re-compile, pass.

However, shipping your project will collapse (provided your project uses the Sdwebimage function). You also need to add the link option:-O BJC.

If the operation still fails at this point, you will also need to add a reference to Imageio.framework in "buildphases".

code example:

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

-(uitableviewcell*) TableView: (UITableView *) TableView

Cellforrowatindexpath: ( Nsindexpath *) Indexpath

{

Static NSString *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 Image    

[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  to load the web image
Sd_setimagewithurl:
[nsurlurlwithstring:@ "http://www.domain.com/path/to/image.jpg  "]
Placeholderimage:imagenamed:@ "placeholder.png"
Completed:nserrornsurl  *imageurl) {
... completion code here ...
}
];

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Getting Started with Sdwebimage

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.