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.