Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Sep 12, 2015
1 parent b3be66c commit 6c772ff
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ DFImageManager is a [pipeline](#h_design) that loads images using pluggable comp

```objective-c
[[[DFImageManager sharedManager] imageTaskForResource:[NSURL URLWithString:@"http://..."] completion:^(UIImage *image, NSError *error, DFImageResponse *response, DFImageTask *task){
// Use loaded image
// Use loaded image
}] resume];
```
Expand All @@ -80,10 +80,10 @@ options.allowsClipping = YES;
DFImageRequest *request = [DFImageRequest requestWithResource:imageURL targetSize:CGSizeMake(100.f, 100.f) contentMode:DFImageContentModeAspectFill options:options.options];
[[[DFImageManager sharedManager] imageTaskForRequest:request completion:^(UIImage *image, NSError *error, DFImageResponse *response, DFImageTask *imageTask) {
// Image is resized and clipped to fill 100x100px square
if (response.isFastResponse) {
// Image was returned synchronously from the memory cache
}
// Image is resized and clipped to fill 100x100px square
if (response.isFastResponse) {
// Image was returned synchronously from the memory cache
}
}] resume];
```

Expand Down Expand Up @@ -124,28 +124,28 @@ imageView.managesRequestPriorities = YES; // Automatically changes current reque
```objective-c
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:<#reuse_id#> forIndexPath:indexPath];
cell.backgroundColor = [UIColor colorWithWhite:235.f/255.f alpha:1.f];
DFImageView *imageView = (id)[cell viewWithTag:15];
if (!imageView) {
imageView = [[DFImageView alloc] initWithFrame:cell.bounds];
imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
imageView.tag = 15;
[cell addSubview:imageView];
}
[imageView prepareForReuse];
[imageView setImageWithResource:<#image_url#>];
return cell;
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:<#reuse_id#> forIndexPath:indexPath];
cell.backgroundColor = [UIColor colorWithWhite:235.f/255.f alpha:1.f];
DFImageView *imageView = (id)[cell viewWithTag:15];
if (!imageView) {
imageView = [[DFImageView alloc] initWithFrame:cell.bounds];
imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
imageView.tag = 15;
[cell addSubview:imageView];
}
[imageView prepareForReuse];
[imageView setImageWithResource:<#image_url#>];
return cell;
}
```

Cancel image task as soon as the cell goes offscreen (optional):

```objective-c
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
DFImageView *imageView = (id)[cell viewWithTag:15];
[imageView prepareForReuse];
DFImageView *imageView = (id)[cell viewWithTag:15];
[imageView prepareForReuse];
}
```

Expand All @@ -165,7 +165,7 @@ NSArray *requestsForRemovedItems = ...; // Create image requests
PHAsset *asset = ...;
DFImageRequest *request = [DFImageRequest requestWithResource:asset targetSize:CGSizeMake(100.f, 100.f) contentMode:DFImageContentModeAspectFill options:nil];
[[[DFImageManager sharedManager] imageTaskForRequest:request completion:^(UIImage *image, NSDictionary *info) {
// Image resized to 100x100px square
// Image resized to 100x100px square
}] resume];
```

Expand All @@ -182,7 +182,7 @@ DFImageRequest *request = // Create request with given options

DFImageTask *imageTask = .../ Create image task
imageTask.progressiveImageHandler = ^(UIImage *__nonnull image){
imageView.image = image;
imageView.image = image;
};

[imageTask resume];
Expand Down

0 comments on commit 6c772ff

Please sign in to comment.