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 <SDWebImage/UIImageView+WebCache.h>
|
|
|
|
#import "DetailViewController.h"
|
2016-06-01 15:06:37 +08:00
|
|
|
#import <SDWebImage/FLAnimatedImageView.h>
|
|
|
|
#import <SDWebImage/FLAnimatedImageView+WebCache.h>
|
2016-09-26 00:44:52 +08:00
|
|
|
#import <SDWebImage/UIView+WebCache.h>
|
2016-06-01 15:06:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
@interface MyCustomTableViewCell : UITableViewCell
|
|
|
|
|
|
|
|
@property (nonatomic, strong) UILabel *customTextLabel;
|
|
|
|
@property (nonatomic, strong) FLAnimatedImageView *customImageView;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@implementation MyCustomTableViewCell
|
|
|
|
|
|
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
|
|
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
|
|
|
_customImageView = [[FLAnimatedImageView alloc] initWithFrame:CGRectMake(20.0, 2.0, 60.0, 40.0)];
|
|
|
|
[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
|
|
|
|
|
|
|
|
|
2012-05-10 06:30:48 +08:00
|
|
|
|
|
|
|
@interface MasterViewController () {
|
2016-01-21 21:36:36 +08:00
|
|
|
NSMutableArray *_objects;
|
2012-05-10 06:30:48 +08:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation MasterViewController
|
|
|
|
|
|
|
|
@synthesize detailViewController = _detailViewController;
|
|
|
|
|
2016-05-23 12:58:02 +08:00
|
|
|
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
|
2012-05-10 06:30:48 +08:00
|
|
|
{
|
|
|
|
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
[SDWebImageManager sharedManager].imageDownloader.username = @"httpwatch";
|
|
|
|
[SDWebImageManager sharedManager].imageDownloader.password = @"httpwatch01";
|
|
|
|
|
2016-01-21 21:36:36 +08:00
|
|
|
_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",
|
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",
|
2016-09-24 01:12:13 +08:00
|
|
|
@"https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png",
|
2017-10-21 01:29:18 +08:00
|
|
|
@"http://via.placeholder.com/200x200.jpg"
|
2012-05-10 06:30:48 +08:00
|
|
|
nil];
|
2016-01-21 21:36:36 +08:00
|
|
|
|
|
|
|
for (int i=0; i<100; i++) {
|
|
|
|
[_objects addObject:[NSString stringWithFormat:@"https://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage%03d.jpg", i]];
|
|
|
|
}
|
|
|
|
|
2012-05-10 06:30:48 +08:00
|
|
|
}
|
2013-02-17 06:33:41 +08:00
|
|
|
[SDWebImageManager.sharedManager.imageDownloader setValue:@"SDWebImage Demo" forHTTPHeaderField:@"AppName"];
|
2013-03-28 00:43:42 +08:00
|
|
|
SDWebImageManager.sharedManager.imageDownloader.executionOrder = SDWebImageDownloaderLIFOExecutionOrder;
|
2012-05-10 06:30:48 +08:00
|
|
|
return self;
|
|
|
|
}
|
2012-11-06 06:00:50 +08:00
|
|
|
|
|
|
|
- (void)flushCache
|
|
|
|
{
|
|
|
|
[SDWebImageManager.sharedManager.imageCache clearMemory];
|
2016-09-24 02:15:38 +08:00
|
|
|
[SDWebImageManager.sharedManager.imageCache clearDiskOnCompletion:nil];
|
2012-11-06 06:00:50 +08:00
|
|
|
}
|
2012-05-10 06:30:48 +08:00
|
|
|
|
|
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
|
|
|
{
|
|
|
|
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Table View
|
|
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
|
|
{
|
|
|
|
return _objects.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
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];
|
2012-05-10 06:30:48 +08:00
|
|
|
}
|
|
|
|
|
2016-10-01 02:36:34 +08:00
|
|
|
[cell.customImageView sd_setShowActivityIndicatorView:YES];
|
|
|
|
[cell.customImageView sd_setIndicatorStyle:UIActivityIndicatorViewStyleGray];
|
2016-06-01 15:06:37 +08:00
|
|
|
|
|
|
|
cell.customTextLabel.text = [NSString stringWithFormat:@"Image #%ld", (long)indexPath.row];
|
2016-06-01 15:11:46 +08:00
|
|
|
[cell.customImageView sd_setImageWithURL:[NSURL URLWithString:_objects[indexPath.row]]
|
|
|
|
placeholderImage:placeholderImage
|
|
|
|
options:indexPath.row == 0 ? SDWebImageRefreshCached : 0];
|
2012-05-10 06:30:48 +08:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
if (!self.detailViewController)
|
|
|
|
{
|
|
|
|
self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
|
|
|
|
}
|
2016-05-23 12:58:02 +08:00
|
|
|
NSString *largeImageURL = [_objects[indexPath.row] stringByReplacingOccurrencesOfString:@"small" withString:@"source"];
|
2012-05-10 06:30:48 +08:00
|
|
|
self.detailViewController.imageURL = [NSURL URLWithString:largeImageURL];
|
|
|
|
[self.navigationController pushViewController:self.detailViewController animated:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|