Imageのキャッシュ機能が使えるSDWebImageを組み込んでみました。
今回は、UIButtonにセットするImageをキャッシュさせたかったので、以下のように実装。
<SDWebImage/UIButton+WebCache.h>
NSString *url;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button sd_setImageWithURL:[NSURL URLWithString:url]
forState:UIControlStateNormal
placeholderImage:nil
options:SDWebImageRetryFailed
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
}];backgroundの時は、<SDWebImage/UIButton+WebCache.h>
NSString *url;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button sd_setBackgroundImageWithURL:[NSURL URLWithString:url]
forState:UIControlStateNormal
placeholderImage:nil
options:SDWebImageRetryFailed
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
}];これいい。
0 コメント:
コメントを投稿