Merge pull request #20 from exalted/master
Added UIButton+WebCache category
Showing
2 changed files
with
62 additions
and
0 deletions
UIButton+WebCache.h
0 → 100644
1 | +/* | ||
2 | + * This file is part of the SDWebImage package. | ||
3 | + * (c) Olivier Poitrey <rs@dailymotion.com> | ||
4 | + * | ||
5 | + * For the full copyright and license information, please view the LICENSE | ||
6 | + * file that was distributed with this source code. | ||
7 | + */ | ||
8 | + | ||
9 | +#import "SDWebImageCompat.h" | ||
10 | +#import "SDWebImageManagerDelegate.h" | ||
11 | + | ||
12 | +@interface UIButton (WebCache) <SDWebImageManagerDelegate> | ||
13 | + | ||
14 | +- (void)setImageWithURL:(NSURL *)url; | ||
15 | +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; | ||
16 | +- (void)cancelCurrentImageLoad; | ||
17 | + | ||
18 | +@end |
UIButton+WebCache.m
0 → 100644
1 | +/* | ||
2 | + * This file is part of the SDWebImage package. | ||
3 | + * (c) Olivier Poitrey <rs@dailymotion.com> | ||
4 | + * | ||
5 | + * For the full copyright and license information, please view the LICENSE | ||
6 | + * file that was distributed with this source code. | ||
7 | + */ | ||
8 | + | ||
9 | +#import "UIButton+WebCache.h" | ||
10 | +#import "SDWebImageManager.h" | ||
11 | + | ||
12 | +@implementation UIButton (WebCache) | ||
13 | + | ||
14 | +- (void)setImageWithURL:(NSURL *)url | ||
15 | +{ | ||
16 | + [self setImageWithURL:url placeholderImage:nil]; | ||
17 | +} | ||
18 | + | ||
19 | +- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder | ||
20 | +{ | ||
21 | + SDWebImageManager *manager = [SDWebImageManager sharedManager]; | ||
22 | + | ||
23 | + // Remove in progress downloader from queue | ||
24 | + [manager cancelForDelegate:self]; | ||
25 | + | ||
26 | + [self setImage:placeholder forState:UIControlStateNormal]; | ||
27 | + | ||
28 | + if (url) | ||
29 | + { | ||
30 | + [manager downloadWithURL:url delegate:self]; | ||
31 | + } | ||
32 | +} | ||
33 | + | ||
34 | +- (void)cancelCurrentImageLoad | ||
35 | +{ | ||
36 | + [[SDWebImageManager sharedManager] cancelForDelegate:self]; | ||
37 | +} | ||
38 | + | ||
39 | +- (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UIImage *)image | ||
40 | +{ | ||
41 | + [self setImage:image forState:UIControlStateNormal]; | ||
42 | +} | ||
43 | + | ||
44 | +@end |
-
Please register or login to post a comment