2016-06-01 20:53:08 +08:00
|
|
|
/*
|
|
|
|
* This file is part of the SDWebImage package.
|
|
|
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
2012-05-10 06:30:48 +08:00
|
|
|
|
|
|
|
#import "MasterViewController.h"
|
|
|
|
#import "DetailViewController.h"
|
2018-04-19 16:23:17 +08:00
|
|
|
#import <SDWebImage/SDWebImage.h>
|
2016-06-01 15:06:37 +08:00
|
|
|
|
|
|
|
@interface MyCustomTableViewCell : UITableViewCell
|
|
|
|
|
|
|
|
@property (nonatomic, strong) UILabel *customTextLabel;
|
2017-12-21 11:43:46 +08:00
|
|
|
@property (nonatomic, strong) SDAnimatedImageView *customImageView;
|
2016-06-01 15:06:37 +08:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation MyCustomTableViewCell
|
|
|
|
|
|
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
|
|
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
2017-12-21 11:43:46 +08:00
|
|
|
_customImageView = [[SDAnimatedImageView alloc] initWithFrame:CGRectMake(20.0, 2.0, 60.0, 40.0)];
|
2016-06-01 15:06:37 +08:00
|
|
|
[self.contentView addSubview:_customImageView];
|
|
|
|
_customTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(100.0, 12.0, 200, 20.0)];
|
|
|
|
[self.contentView addSubview:_customTextLabel];
|
|
|
|
|
|
|
|
_customImageView.clipsToBounds = YES;
|
|
|
|
_customImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2017-11-05 06:30:43 +08:00
|
|
|
@interface MasterViewController ()
|
2016-06-01 15:06:37 +08:00
|
|
|
|
2017-11-05 06:30:43 +08:00
|
|
|
@property (nonatomic, strong) NSMutableArray<NSString *> *objects;
|
2012-05-10 06:30:48 +08:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation MasterViewController
|
|
|
|
|
2018-08-29 18:54:48 +08:00
|
|
|
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
2012-05-10 06:30:48 +08:00
|
|
|
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
2018-08-29 18:54:48 +08:00
|
|
|
if (self) {
|
2012-05-10 06:30:48 +08:00
|
|
|
self.title = @"SDWebImage";
|
2012-11-06 06:00:50 +08:00
|
|
|
self.navigationItem.rightBarButtonItem = [UIBarButtonItem.alloc initWithTitle:@"Clear Cache"
|
|
|
|
style:UIBarButtonItemStylePlain
|
|
|
|
target:self
|
|
|
|
action:@selector(flushCache)];
|
2014-06-24 02:57:33 +08:00
|
|
|
|
|
|
|
// HTTP NTLM auth example
|
|
|
|
// Add your NTLM image url to the array below and replace the credentials
|
2018-04-15 16:40:42 +08:00
|
|
|
[SDWebImageDownloader sharedDownloader].config.username = @"httpwatch";
|
|
|
|
[SDWebImageDownloader sharedDownloader].config.password = @"httpwatch01";
|
|
|
|
[[SDWebImageDownloader sharedDownloader] setValue:@"SDWebImage Demo" forHTTPHeaderField:@"AppName"];
|
|
|
|
[SDWebImageDownloader sharedDownloader].config.executionOrder = SDWebImageDownloaderLIFOExecutionOrder;
|
2014-06-24 02:57:33 +08:00
|
|
|
|
2017-11-05 06:30:43 +08:00
|
|
|
self.objects = [NSMutableArray arrayWithObjects:
|
2014-06-24 02:57:33 +08:00
|
|
|
@"http://www.httpwatch.com/httpgallery/authentication/authenticatedimage/default.aspx?0.35786508303135633", // requires HTTP auth, used to demo the NTLM auth
|
2013-04-29 05:06:54 +08:00
|
|
|
@"http://assets.sbnation.com/assets/2512203/dogflops.gif",
|
2016-06-01 15:06:37 +08:00
|
|
|
@"https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif",
|
2018-03-29 19:42:33 +08:00
|
|
|
@"http://apng.onevcat.com/assets/elephant.png",
|
2013-06-08 02:38:16 +08:00
|
|
|
@"http://www.ioncannon.net/wp-content/uploads/2011/06/test2.webp",
|
|
|
|
@"http://www.ioncannon.net/wp-content/uploads/2011/06/test9.webp",
|
2016-01-15 23:48:44 +08:00
|
|
|
@"http://littlesvr.ca/apng/images/SteamEngine.webp",
|
|
|
|
@"http://littlesvr.ca/apng/images/world-cup-2014-42.webp",
|
2017-07-31 21:28:02 +08:00
|
|
|
@"https://isparta.github.io/compare-webp/image/gif_webp/webp/2.webp",
|
2018-08-06 17:53:24 +08:00
|
|
|
@"https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic",
|
2019-09-22 14:29:54 +08:00
|
|
|
@"https://nokiatech.github.io/heif/content/image_sequences/starfield_animation.heic",
|
2019-11-22 16:16:20 +08:00
|
|
|
@"https://s2.ax1x.com/2019/11/01/KHYIgJ.gif",
|
2020-01-30 15:29:57 +08:00
|
|
|
@"https://raw.githubusercontent.com/icons8/flat-color-icons/master/pdf/stack_of_photos.pdf",
|
2016-09-24 01:12:13 +08:00
|
|
|
@"https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png",
|
2022-10-27 11:09:29 +08:00
|
|
|
@"https://res.cloudinary.com/dwpjzbyux/raw/upload/v1666474070/RawDemo/raw_vebed5.NEF",
|
2023-11-16 18:37:04 +08:00
|
|
|
@"https://placehold.co/200x200.jpg",
|
2012-05-10 06:30:48 +08:00
|
|
|
nil];
|
2016-01-21 21:36:36 +08:00
|
|
|
|
2019-05-29 15:12:14 +08:00
|
|
|
for (int i=1; i<25; i++) {
|
|
|
|
// From http://r0k.us/graphics/kodak/, 768x512 resolution, 24 bit depth PNG
|
|
|
|
[self.objects addObject:[NSString stringWithFormat:@"http://r0k.us/graphics/kodak/kodak/kodim%02d.png", i]];
|
2016-01-21 21:36:36 +08:00
|
|
|
}
|
2012-05-10 06:30:48 +08:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
2012-11-06 06:00:50 +08:00
|
|
|
|
2018-08-29 18:54:48 +08:00
|
|
|
- (void)flushCache {
|
2018-04-13 18:52:46 +08:00
|
|
|
[SDWebImageManager.sharedManager.imageCache clearWithCacheType:SDImageCacheTypeAll completion:nil];
|
2012-11-06 06:00:50 +08:00
|
|
|
}
|
2012-05-10 06:30:48 +08:00
|
|
|
|
|
|
|
#pragma mark - Table View
|
|
|
|
|
2018-08-29 18:54:48 +08:00
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
2017-11-05 06:30:43 +08:00
|
|
|
return self.objects.count;
|
2012-05-10 06:30:48 +08:00
|
|
|
}
|
|
|
|
|
2018-08-29 18:54:48 +08:00
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
2012-05-10 06:30:48 +08:00
|
|
|
static NSString *CellIdentifier = @"Cell";
|
|
|
|
|
2016-06-01 15:06:37 +08:00
|
|
|
static UIImage *placeholderImage = nil;
|
|
|
|
if (!placeholderImage) {
|
|
|
|
placeholderImage = [UIImage imageNamed:@"placeholder"];
|
|
|
|
}
|
|
|
|
|
|
|
|
MyCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
|
|
|
if (cell == nil) {
|
|
|
|
cell = [[MyCustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
|
2018-01-17 15:20:38 +08:00
|
|
|
cell.customImageView.sd_imageTransition = SDWebImageTransition.fadeTransition;
|
2018-01-20 23:40:16 +08:00
|
|
|
cell.customImageView.sd_imageIndicator = SDWebImageActivityIndicator.grayIndicator;
|
2012-05-10 06:30:48 +08:00
|
|
|
}
|
2016-06-01 15:06:37 +08:00
|
|
|
|
|
|
|
cell.customTextLabel.text = [NSString stringWithFormat:@"Image #%ld", (long)indexPath.row];
|
2020-01-30 18:33:16 +08:00
|
|
|
__weak SDAnimatedImageView *imageView = cell.customImageView;
|
|
|
|
[imageView sd_setImageWithURL:[NSURL URLWithString:self.objects[indexPath.row]]
|
|
|
|
placeholderImage:placeholderImage
|
2021-03-09 14:33:00 +08:00
|
|
|
options:0
|
2020-01-30 18:33:16 +08:00
|
|
|
context:@{SDWebImageContextImageThumbnailPixelSize : @(CGSizeMake(180, 120))}
|
|
|
|
progress:nil
|
|
|
|
completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
|
|
|
|
SDWebImageCombinedOperation *operation = [imageView sd_imageLoadOperationForKey:imageView.sd_latestOperationKey];
|
|
|
|
SDWebImageDownloadToken *token = operation.loaderOperation;
|
|
|
|
if (@available(iOS 10.0, *)) {
|
|
|
|
NSURLSessionTaskMetrics *metrics = token.metrics;
|
|
|
|
if (metrics) {
|
|
|
|
printf("Metrics: %s download in (%f) seconds\n", [imageURL.absoluteString cStringUsingEncoding:NSUTF8StringEncoding], metrics.taskInterval.duration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}];
|
2012-05-10 06:30:48 +08:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2018-08-29 18:54:48 +08:00
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
2017-11-05 06:30:43 +08:00
|
|
|
NSString *largeImageURLString = [self.objects[indexPath.row] stringByReplacingOccurrencesOfString:@"small" withString:@"source"];
|
|
|
|
NSURL *largeImageURL = [NSURL URLWithString:largeImageURLString];
|
|
|
|
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
|
|
|
|
detailViewController.imageURL = largeImageURL;
|
|
|
|
[self.navigationController pushViewController:detailViewController animated:YES];
|
2012-05-10 06:30:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|