Skip to content

Instantly share code, notes, and snippets.

@kanekomasanori
Created January 22, 2016 02:00
Show Gist options
  • Save kanekomasanori/30837a4b4a0171988e0b to your computer and use it in GitHub Desktop.
Save kanekomasanori/30837a4b4a0171988e0b to your computer and use it in GitHub Desktop.
import UIKit
import SDWebImage
extension UIImageView {
func sd_setFadeImageWithURL(url: NSURL!, placeholderImage: UIImage!) {
if let placeholderImage = placeholderImage {
sd_setImageWithURL(url, placeholderImage: placeholderImage, options: .AvoidAutoSetImage) { (image, error, cache, url) -> Void in
if cache == SDImageCacheType.None {
UIView.transitionWithView(self, duration: 0.35, options: [.TransitionCrossDissolve, .CurveEaseOut], animations: { () -> Void in
self.image = image
}, completion: nil)
} else {
self.image = image
}
}
} else {
sd_setImageWithURL(url)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment