Authored by DreamPiggy

Update macOS demo to add a clear cache button using NSButton category

  1 +{
  2 + "info" : {
  3 + "version" : 1,
  4 + "author" : "xcode"
  5 + }
  6 +}
1 -<?xml version="1.0" encoding="UTF-8" standalone="no"?>  
2 -<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS"> 1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
3 <dependencies> 3 <dependencies>
4 <deployment identifier="macosx"/> 4 <deployment identifier="macosx"/>
5 - <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/> 5 + <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13771"/>
  6 + <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
6 </dependencies> 7 </dependencies>
7 <scenes> 8 <scenes>
8 <!--Application--> 9 <!--Application-->
@@ -656,6 +657,9 @@ @@ -656,6 +657,9 @@
656 <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/> 657 <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
657 <rect key="contentRect" x="196" y="240" width="480" height="400"/> 658 <rect key="contentRect" x="196" y="240" width="480" height="400"/>
658 <rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/> 659 <rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
  660 + <connections>
  661 + <outlet property="delegate" destination="B8D-0N-5wS" id="1ov-0o-Na3"/>
  662 + </connections>
659 </window> 663 </window>
660 <connections> 664 <connections>
661 <segue destination="XfG-lQ-9wD" kind="relationship" relationship="window.shadowedContentViewController" id="cq2-FE-JQM"/> 665 <segue destination="XfG-lQ-9wD" kind="relationship" relationship="window.shadowedContentViewController" id="cq2-FE-JQM"/>
@@ -675,23 +679,36 @@ @@ -675,23 +679,36 @@
675 <subviews> 679 <subviews>
676 <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="nbD-Cx-g7b"> 680 <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="nbD-Cx-g7b">
677 <rect key="frame" x="20" y="252" width="204" height="128"/> 681 <rect key="frame" x="20" y="252" width="204" height="128"/>
  682 + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
678 <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="vAn-1d-apO"/> 683 <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="vAn-1d-apO"/>
679 </imageView> 684 </imageView>
680 <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kv0-67-hkh"> 685 <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kv0-67-hkh">
681 <rect key="frame" x="256" y="252" width="204" height="128"/> 686 <rect key="frame" x="256" y="252" width="204" height="128"/>
  687 + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
682 <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="f0P-c9-GMe"/> 688 <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="f0P-c9-GMe"/>
683 </imageView> 689 </imageView>
684 <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="JIp-Or-vBM"> 690 <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="JIp-Or-vBM">
685 <rect key="frame" x="20" y="116" width="204" height="128"/> 691 <rect key="frame" x="20" y="116" width="204" height="128"/>
  692 + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
686 <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="NJq-m3-LlB"/> 693 <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="NJq-m3-LlB"/>
687 </imageView> 694 </imageView>
688 <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="khI-tY-l0M"> 695 <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="khI-tY-l0M">
689 <rect key="frame" x="256" y="116" width="204" height="128"/> 696 <rect key="frame" x="256" y="116" width="204" height="128"/>
  697 + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
690 <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="WbV-Do-9qy"/> 698 <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="WbV-Do-9qy"/>
691 </imageView> 699 </imageView>
  700 + <button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="NqE-Zi-qhY">
  701 + <rect key="frame" x="212" y="17" width="56" height="31"/>
  702 + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
  703 + <buttonCell key="cell" type="bevel" title="Clear" bezelStyle="regularSquare" alignment="center" borderStyle="border" imageScaling="proportionallyUpOrDown" inset="2" id="OYN-fG-Plb">
  704 + <behavior key="behavior" pushIn="YES" changeContents="YES" lightByContents="YES"/>
  705 + <font key="font" metaFont="system"/>
  706 + </buttonCell>
  707 + </button>
692 </subviews> 708 </subviews>
693 </view> 709 </view>
694 <connections> 710 <connections>
  711 + <outlet property="clearCacheButton" destination="NqE-Zi-qhY" id="eoz-cU-wWs"/>
695 <outlet property="imageView1" destination="nbD-Cx-g7b" id="t2R-8w-ybH"/> 712 <outlet property="imageView1" destination="nbD-Cx-g7b" id="t2R-8w-ybH"/>
696 <outlet property="imageView2" destination="kv0-67-hkh" id="i4k-5c-bno"/> 713 <outlet property="imageView2" destination="kv0-67-hkh" id="i4k-5c-bno"/>
697 <outlet property="imageView3" destination="JIp-Or-vBM" id="Qcf-og-59T"/> 714 <outlet property="imageView3" destination="JIp-Or-vBM" id="Qcf-og-59T"/>
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 @property (weak) IBOutlet NSImageView *imageView2; 16 @property (weak) IBOutlet NSImageView *imageView2;
17 @property (weak) IBOutlet NSImageView *imageView3; 17 @property (weak) IBOutlet NSImageView *imageView3;
18 @property (weak) IBOutlet NSImageView *imageView4; 18 @property (weak) IBOutlet NSImageView *imageView4;
  19 +@property (weak) IBOutlet NSButton *clearCacheButton;
19 20
20 @end 21 @end
21 22
@@ -36,6 +37,20 @@ @@ -36,6 +37,20 @@
36 self.imageView4.wantsLayer = YES; 37 self.imageView4.wantsLayer = YES;
37 self.imageView4.sd_imageTransition = SDWebImageTransition.fadeTransition; 38 self.imageView4.sd_imageTransition = SDWebImageTransition.fadeTransition;
38 [self.imageView4 sd_setImageWithURL:[NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage001.jpg"] placeholderImage:nil options:SDWebImageForceTransition]; 39 [self.imageView4 sd_setImageWithURL:[NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage001.jpg"] placeholderImage:nil options:SDWebImageForceTransition];
  40 +
  41 + self.clearCacheButton.target = self;
  42 + self.clearCacheButton.action = @selector(clearCacheButtonClicked:);
  43 + [self.clearCacheButton sd_setImageWithURL:[NSURL URLWithString:@"https://png.icons8.com/color/100/000000/delete-sign.png"]];
  44 + [self.clearCacheButton sd_setAlternateImageWithURL:[NSURL URLWithString:@"https://png.icons8.com/color/100/000000/checkmark.png"]];
  45 +}
  46 +
  47 +- (void)clearCacheButtonClicked:(NSResponder *)sender {
  48 + NSButton *button = (NSButton *)sender;
  49 + button.state = NSControlStateValueOn;
  50 + [[SDImageCache sharedImageCache] clearMemory];
  51 + [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
  52 + button.state = NSControlStateValueOff;
  53 + }];
39 } 54 }
40 55
41 - (void)setRepresentedObject:(id)representedObject { 56 - (void)setRepresentedObject:(id)representedObject {