ViewController.m
2.99 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
//
// 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+WebCache.h"
@interface ViewController ()
@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"]];
}
- (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