Skip to content

Commit

Permalink
添加按钮的图片缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
songwentong committed Jul 30, 2014
1 parent 75b6acf commit c6adc9c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
6 changes: 6 additions & 0 deletions WTRequestCenter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
A3B70EFC198888BC002776F4 /* UIImageView+WTImageCache.m in Sources */ = {isa = PBXBuildFile; fileRef = A3B70EFB198888BC002776F4 /* UIImageView+WTImageCache.m */; };
A3B70F591988BDFA002776F4 /* image.jpg in Resources */ = {isa = PBXBuildFile; fileRef = A3B70F581988BDFA002776F4 /* image.jpg */; };
A3B70F5E1988DB9F002776F4 /* UIButton+WTImageCache.m in Sources */ = {isa = PBXBuildFile; fileRef = A3B70F5D1988DB9F002776F4 /* UIButton+WTImageCache.m */; };
E4440D71197A01B1001E6D88 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4440D70197A01B1001E6D88 /* Foundation.framework */; };
E4440D73197A01B1001E6D88 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4440D72197A01B1001E6D88 /* CoreGraphics.framework */; };
E4440D75197A01B1001E6D88 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4440D74197A01B1001E6D88 /* UIKit.framework */; };
Expand Down Expand Up @@ -40,6 +41,8 @@
A3B70EFA198888BC002776F4 /* UIImageView+WTImageCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImageView+WTImageCache.h"; sourceTree = "<group>"; };
A3B70EFB198888BC002776F4 /* UIImageView+WTImageCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+WTImageCache.m"; sourceTree = "<group>"; };
A3B70F581988BDFA002776F4 /* image.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = image.jpg; sourceTree = "<group>"; };
A3B70F5C1988DB9F002776F4 /* UIButton+WTImageCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIButton+WTImageCache.h"; sourceTree = "<group>"; };
A3B70F5D1988DB9F002776F4 /* UIButton+WTImageCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIButton+WTImageCache.m"; sourceTree = "<group>"; };
E4440D6D197A01B1001E6D88 /* WTRequestCenter.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WTRequestCenter.app; sourceTree = BUILT_PRODUCTS_DIR; };
E4440D70197A01B1001E6D88 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
E4440D72197A01B1001E6D88 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -169,6 +172,8 @@
E4DBC943197D14F3004F9393 /* WTRequestCenter.m */,
A3B70EFA198888BC002776F4 /* UIImageView+WTImageCache.h */,
A3B70EFB198888BC002776F4 /* UIImageView+WTImageCache.m */,
A3B70F5C1988DB9F002776F4 /* UIButton+WTImageCache.h */,
A3B70F5D1988DB9F002776F4 /* UIButton+WTImageCache.m */,
);
name = WTRequestCenter;
path = WTRequestCenter/WTRequestCenter;
Expand Down Expand Up @@ -277,6 +282,7 @@
E4DBC944197D14F3004F9393 /* WTRequestCenter.m in Sources */,
E4440D81197A01B1001E6D88 /* AppDelegate.m in Sources */,
E4440D7D197A01B1001E6D88 /* main.m in Sources */,
A3B70F5E1988DB9F002776F4 /* UIButton+WTImageCache.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>237BBC04-2FFA-484F-AAF2-0F61BEE282C3</string>
<string>682BFD67-F673-4FA7-B8F6-B111BD6A588E</string>
<key>IDESourceControlProjectName</key>
<string>WTRequestCenter</string>
<key>IDESourceControlProjectOriginsDictionary</key>
Expand Down
Binary file not shown.
19 changes: 19 additions & 0 deletions WTRequestCenter/WTRequestCenter/UIButton+WTImageCache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// UIButton+WTImageCache.h
// WTRequestCenter
//
// Created by songwt on 14-7-30.
// Copyright (c) 2014年 song. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIButton (WTImageCache)

- (void)setImageForState:(UIControlState)state
withURL:(NSURL *)url;

- (void)setImageForState:(UIControlState)state
withURL:(NSURL *)url
placeholderImage:(UIImage *)placeholderImage;
@end
27 changes: 27 additions & 0 deletions WTRequestCenter/WTRequestCenter/UIButton+WTImageCache.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// UIButton+WTImageCache.m
// WTRequestCenter
//
// Created by songwt on 14-7-30.
// Copyright (c) 2014年 song. All rights reserved.
//

#import "UIButton+WTImageCache.h"
#import "WTRequestCenter.h"
@implementation UIButton (WTImageCache)

- (void)setImageForState:(UIControlState)state
withURL:(NSURL *)url
{
[self setImageForState:state withURL:url placeholderImage:nil];
}
- (void)setImageForState:(UIControlState)state
withURL:(NSURL *)url
placeholderImage:(UIImage *)placeholderImage
{
[self setImage:placeholderImage forState:state];
[WTRequestCenter getImageWithURL:url completionHandler:^(UIImage *image) {
[self setImage:image forState:state];
}];
}
@end

0 comments on commit c6adc9c

Please sign in to comment.