ViewController.m 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #import "ViewController.h"
  9. @import SDWebImage;
  10. @interface ViewController ()
  11. @property (weak) IBOutlet NSImageView *imageView1;
  12. @property (weak) IBOutlet NSImageView *imageView2;
  13. @property (weak) IBOutlet NSImageView *imageView3;
  14. @property (weak) IBOutlet NSImageView *imageView4;
  15. @property (weak) IBOutlet NSButton *clearCacheButton;
  16. @end
  17. @implementation ViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. //Add GIF coder for better animated image rendering
  21. [[SDWebImageCodersManager sharedInstance] addCoder:[SDWebImageGIFCoder sharedCoder]];
  22. // NOTE: https links or authentication ones do not work (there is a crash)
  23. // Do any additional setup after loading the view.
  24. // For animated GIF rendering, set `animates` to YES or will only show the first frame
  25. self.imageView1.animates = YES;
  26. self.imageView3.animates = YES;
  27. [self.imageView1 sd_setImageWithURL:[NSURL URLWithString:@"http://assets.sbnation.com/assets/2512203/dogflops.gif"]];
  28. [self.imageView2 sd_setImageWithURL:[NSURL URLWithString:@"http://www.ioncannon.net/wp-content/uploads/2011/06/test2.webp"]];
  29. [self.imageView3 sd_setImageWithURL:[NSURL URLWithString:@"http://littlesvr.ca/apng/images/SteamEngine.webp"]];
  30. self.imageView4.wantsLayer = YES;
  31. self.imageView4.sd_imageTransition = SDWebImageTransition.fadeTransition;
  32. [self.imageView4 sd_setImageWithURL:[NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage001.jpg"] placeholderImage:nil options:SDWebImageForceTransition];
  33. self.clearCacheButton.target = self;
  34. self.clearCacheButton.action = @selector(clearCacheButtonClicked:);
  35. [self.clearCacheButton sd_setImageWithURL:[NSURL URLWithString:@"https://png.icons8.com/color/100/000000/delete-sign.png"]];
  36. [self.clearCacheButton sd_setAlternateImageWithURL:[NSURL URLWithString:@"https://png.icons8.com/color/100/000000/checkmark.png"]];
  37. }
  38. - (void)clearCacheButtonClicked:(NSResponder *)sender {
  39. NSButton *button = (NSButton *)sender;
  40. button.state = NSControlStateValueOn;
  41. [[SDImageCache sharedImageCache] clearMemory];
  42. [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
  43. button.state = NSControlStateValueOff;
  44. }];
  45. }
  46. - (void)setRepresentedObject:(id)representedObject {
  47. [super setRepresentedObject:representedObject];
  48. // Update the view, if already loaded.
  49. }
  50. @end