IOS SDWebImage

1.SDWebImage安装配置一

下载SDWebImage:https://github.com/rs/SDWebImage

Installation

There are two ways to use this in your project: copy all the files into your project, or import the project as a static library.

Add the SDWebImage project to your project

Right-click on the project navigator and select "Add Files to "Your Project":

Add Library Project

In the dialog, select SDWebImage.xcodeproj:

Add Library Project Dialog

After you’ve added the subproject, it’ll appear below the main project in Xcode’s Navigator tree:

Library Added

You may want to add the SDWebImage directory in your project source tree as a submodule before adding it to your project.

Add build target dependencies

In you application project app’s target settings, find the "Build Phases" section and open the "Target Dependencies" block:

Add Target Dependencies

Click the "+" button and select "SDWebImage ARC" (you may choose the non ARC target if you want to support iOS <3 or the ARC+MKAnnotation if you need MapKit category):

Add Target Dependencies Dialog

Open the "Link Binary With Libraries" block:

Add Library Link

Click the "+" button and select "libSDWebImageARC.a" library (use non ARC version if you chose non ARC version in the previous step):

Add Library Link Dialog

Click the "+" button again and select the "ImageIO.framework", this is needed by the progressive download feature:

Add ImageIO Framework

If you chose to link against the ARC+MKAnnotation target, click the "+" button again and select "MapKit.framework":

Add MapKit Framework

Add headers

Open the "Build Settings" tab, in the "Linking" section, locate the "Other Linker Flags" setting and add the "-ObjC" flag:

Other Linker Flags

In the "Search Paths" section, locate "Header Search Paths" (and not "User Header Search Paths") and add two settings:”$(TARGET_BUILD_DIR)/usr/local/lib/include” and ”$(OBJROOT)/UninstalledProducts/include”. Double click on the<Multiple values> to pop out the box and click on the "+" icon to add each of them. Make sure to include the quotes here:

User Header Search Paths

Import headers in your source files

In the source files where you need to use the library, import the header file:

#import <SDWebImage/UIImageView+WebCache.h>

Build Project

At this point your workspace should build without error. If you are having problem, post to the Issue and the community can help you solve it.

Fixing indexing

If you have problem with auto-completion of SDWebImage methods, you may have to copy the header files in your project.

2.SDWebImage安装配置2

下载:https://github.com/rs/SDWebImage/wiki/Download-Compiled-Framework
 
https://github.com/rs/SDWebImage#installation

Installation

There are two ways to use this in your project: copy all the files into your project, or import the project as a static library.

Add the SDWebImage project to your project

  • Download and unzip the last version of the framework from the download page
  • Right-click on the project navigator and select "Add Files to "Your Project":
  • In the dialog, select SDWebImage.framework:
  • Check the "Copy items into destination group's folder (if needed)" checkbox

Add dependencies

  • In you application project app’s target settings, find the "Build Phases" section and open the "Link Binary With Libraries" block:
  • Click the "+" button again and select the "ImageIO.framework", this is needed by the progressive download feature:

Add Linker Flag

Open the "Build Settings" tab, in the "Linking" section, locate the "Other Linker Flags" setting and add the "-ObjC" flag:

 

Import headers in your source files

In the source files where you need to use the library, import the header file:

#import <SDWebImage/UIImageView+WebCache.h>

Build Project

At this point your workspace should build without error. If you are having problem, post to the Issue and the community can help you solve it.

3.使用

https://github.com/rs/SDWebImage#installation
 1 #import <SDWebImage/UIImageView+WebCache.h>
 2 
 3 ...
 4 
 5 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 6 {
 7     static NSString *MyIdentifier = @"MyIdentifier";
 8 
 9     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
10 
11     if (cell == nil)
12     {
13         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
14                                        reuseIdentifier:MyIdentifier] autorelease];
15     }
16 
17     // Here we use the new provided setImageWithURL: method to load the web image
18     [cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
19                    placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
20 
21     cell.textLabel.text = @"My Text";
22     return cell;
23 }
原文地址:https://www.cnblogs.com/wangshengl9263/p/3347259.html