ViewController.m
5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// ViewController.m
// WSWebImageDemo
//
// Created by 王帅 on 16/7/14.
// Copyright © 2016年 王帅. All rights reserved.
//
#import "ViewController.h"
#import "CNLiveWebImageManager.h"
#import "CNLiveImageCache.h"
#import "UIImageView+CNLiveWebCache.h"
@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
{
NSArray *_imageArray;
}
@property (nonatomic, strong) UIImageView *imageView;
@end
//static NSString *str = @"http://img.firefoxchina.cn/2016/07/4/201607261050080.jpg";
static NSString *str = @"http://desk.fd.zol-img.com.cn/t_s2560x1600c5/g5/M00/0D/0C/ChMkJ1eV8KuIKvxAADO4tztrTKcAAT0ZwCLaesAM7jP146.jpg";
//static NSString *str = @"http://pic104.nipic.com/file/20160720/21897230_115704969000_2.jpg";
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// long long diskCacheSize = [[CNLiveImageCache sharedImageCache] diskCacheSize];
// NSLog(@"%lld",diskCacheSize);
//
// [self.view addSubview:self.imageView];
// [[CNLiveWebImageDownloadManager sharedManager] downloadWebImageWithURL:[NSURL URLWithString:str]
// options:CNLiveWebImageProgressiveDownload
// progress:^(NSInteger receivedSize, NSInteger expectedSize) {
// NSLog(@"receivedSize = %ld, expectedSize = %ld",(long)receivedSize, (long)expectedSize);
// }
// completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
// dispatch_async(dispatch_get_main_queue(), ^{
// self.imageView.image = image;
// });
// }];
// [[CNLiveImageCache sharedImageCache] removeCacheForKey:@"http://img.firefoxchina.cn/2016/07/4/201607261050080.jpg" done:^{
// NSLog(@"Do something");
// }];
// UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 200)];
// imageView.backgroundColor = [UIColor cyanColor];
// [self.view addSubview:imageView];
// [imageView ws_setImageWithUrl:[NSURL URLWithString:str]];
// [imageView ws_setImageWithUrl:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"text.jpg"]];
_imageArray = @[@"http://y1.cnliveimg.com:8080/image/itv/2016/0729/392ab54d87a049b6b7f7cf6d7df252d5_138931_101.jpg",
@"http://y3.cnliveimg.com:8080/image/itv/2016/0729/d56e527238a04a6d909cf080092c3e74_138923_100.jpg",
@"http://y2.cnliveimg.com:8080/image/itv/2016/0729/098609b945fc43169bea7a6093fe449e_138914_100.jpg",
@"http://y3.cnliveimg.com:8080/image/itv/2016/0729/e67a4abf5781407195e6544a1931913c_138913_100.jpg",
@"http://y3.cnliveimg.com:8080/image/itv/2016/0728/912ab18337e642439cfbca32ae527f23_138727_100.jpg",
@"http://y1.cnliveimg.com:8080/image/itv/2016/0722/75be21e738a945e3b6b0437a01437beb_101.jpg",
@"http://y1.cnliveimg.com:8080/image/itv/2016/0520/c4a9729f38f344f599be183bfb0ed0d0_100.jpg",
@"http://y1.cnliveimg.com:8080/image/itv/2016/0429/2237884c0dc64c1bbf486b7c00888cb0_119818_100.jpg",
@"http://y3.cnliveimg.com:8080/image/itv/2016/0405/f7e64bc903884ae3bebbd7493c81759e_115166_100.jpg",
@"http://y1.cnliveimg.com:8080/image/itv/2016/0116/7521576fd18f4bfbaee9efa8d379eee0_101710_100.jpg"];
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(100, 200, 100, 300) style:UITableViewStylePlain];
[self.view addSubview:tableView];
tableView.rowHeight = 100;
tableView.delegate = self;
tableView.dataSource = self;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _imageArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identify = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];
UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[cell.contentView addSubview:image];
image.tag = 1001;
}
UIImageView *imageView = (UIImageView *)[cell viewWithTag:1001];
[imageView ws_setImageWithUrl:[NSURL URLWithString:_imageArray[indexPath.row]] placeholderImage:[UIImage imageNamed:@"text.jpg"]];
return cell;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(UIImageView *)imageView{
if (!_imageView) {
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(40,40,300,200)];
_imageView.backgroundColor = [UIColor redColor];
_imageView.contentMode = UIViewContentModeScaleToFill;
}
return _imageView;
}
@end