// // UIImageView+FLAddition.m // FirstLink // // Created by 王孝道 on 15/5/14. // Copyright (c) 2015年 FirstLink. All rights reserved. // #import "UIImageView+FLAddition.h" #import "UIImageView+WebCache.h" #define kAlphaChangeDuration 0.2f @implementation UIImageView (FLAddition) - (void)fl_setImageWithURL:(NSURL *)url { [self fl_setImageWithURL:url placeholderImage:nil]; } - (void)fl_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { // WeakSelf(weakSelf); [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { // if (!image) { return; } // [UIView transitionWithView:weakSelf // duration:kAlphaChangeDuration // options:UIViewAnimationOptionTransitionCrossDissolve // animations:^{ // weakSelf.image = image; // } completion:NULL]; }]; } - (void)fl_setImageWithURL:(NSString *)urlString finish:(void (^)(CGSize size, NSString *urlString))finishAction { WeakSelf(weakSelf); NSURL *url = [NSURL URLWithString:urlString]; __block typeof(finishAction) weak_finishAction = finishAction; [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (!image) { return; } if (weak_finishAction) weak_finishAction(image.size, urlString); [UIView transitionWithView:weakSelf duration:kAlphaChangeDuration options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ weakSelf.image = image; } completion:NULL]; }]; } - (void)setImageWithURL:(NSString *)urlString placeholderImage:(UIImage *)placeholder width:(CGFloat)width height:(CGFloat)height { NSURL *url; if ([urlString rangeOfString:@"cdn.firstlinkapp.com"].length > 0) { url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", urlString, [FLStringHelper cdnParamaterString:width height:height]]]; } else { url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; } [self fl_setImageWithURL:url placeholderImage:placeholder]; } - (void)setImageWithURL:(NSString *)urlString cdnWidth:(CGFloat)width { urlString = [urlString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; if ([urlString rangeOfString:@"cdn.firstlinkapp.com"].length > 0) { url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", urlString, [FLStringHelper cdnParamaterString:width]]]; } [self fl_setImageWithURL:url placeholderImage:nil]; } @end