Manos Chorianopoulos

MyRewardsBannerOffers dynamic banner image

...@@ -11,19 +11,33 @@ import UIKit ...@@ -11,19 +11,33 @@ import UIKit
11 public class MyRewardsBannerOfferCollectionViewCell: UICollectionViewCell { 11 public class MyRewardsBannerOfferCollectionViewCell: UICollectionViewCell {
12 @IBOutlet weak var backgroundImage: UIImageView! 12 @IBOutlet weak var backgroundImage: UIImageView!
13 13
14 + var postImageURL: String? {
15 + didSet {
16 + if let url = postImageURL {
17 + self.backgroundImage.image = UIImage() // UIImage(named: "loading")
18 +
19 + UIImage.loadImageUsingCacheWithUrlString(url) { image in
20 + // set the image only when we are still displaying the content for the image we finished downloading
21 + if url == self.postImageURL {
22 + self.backgroundImage.image = image
23 + }
24 + }
25 + }
26 + else {
27 + self.backgroundImage.image = nil
28 + }
29 + }
30 + }
31 +
14 public override func awakeFromNib() { 32 public override func awakeFromNib() {
15 super.awakeFromNib() 33 super.awakeFromNib()
16 // Initialization code 34 // Initialization code
35 +
36 + backgroundImage.contentMode = .scaleAspectFill
17 } 37 }
18 38
19 func configureCell(data: CampaignItemModel) { 39 func configureCell(data: CampaignItemModel) {
20 // Use campaign's banner image - no hardcoded defaults 40 // Use campaign's banner image - no hardcoded defaults
21 - let imageName = data._banner_img_mobile ?? "" 41 + self.postImageURL = data._banner_img_mobile ?? ""
22 -
23 - if !imageName.isEmpty {
24 - backgroundImage.image = UIImage(named: imageName, in: Bundle.frameworkResourceBundle, compatibleWith: nil)
25 - } else {
26 - backgroundImage.image = nil
27 - }
28 } 42 }
29 } 43 }
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 <autoresizingMask key="autoresizingMask"/> 17 <autoresizingMask key="autoresizingMask"/>
18 <subviews> 18 <subviews>
19 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="VzF-dQ-3Wa" userLabel="Parent View"> 19 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="VzF-dQ-3Wa" userLabel="Parent View">
20 - <rect key="frame" x="0.0" y="0.0" width="413" height="450"/> 20 + <rect key="frame" x="0.0" y="0.0" width="413" height="465"/>
21 <subviews> 21 <subviews>
22 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="JTs-J5-DO2" userLabel="Top View"> 22 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="JTs-J5-DO2" userLabel="Top View">
23 <rect key="frame" x="24" y="36" width="365" height="35"/> 23 <rect key="frame" x="24" y="36" width="365" height="35"/>
...@@ -106,7 +106,7 @@ ...@@ -106,7 +106,7 @@
106 </constraints> 106 </constraints>
107 </view> 107 </view>
108 <collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="none" translatesAutoresizingMaskIntoConstraints="NO" id="I7z-Fz-SNP"> 108 <collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="none" translatesAutoresizingMaskIntoConstraints="NO" id="I7z-Fz-SNP">
109 - <rect key="frame" x="0.0" y="76" width="413" height="348"/> 109 + <rect key="frame" x="0.0" y="91" width="413" height="348"/>
110 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> 110 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
111 <constraints> 111 <constraints>
112 <constraint firstAttribute="height" constant="348" id="aEf-Xl-A2C"/> 112 <constraint firstAttribute="height" constant="348" id="aEf-Xl-A2C"/>
...@@ -124,7 +124,7 @@ ...@@ -124,7 +124,7 @@
124 </connections> 124 </connections>
125 </collectionView> 125 </collectionView>
126 <pageControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" numberOfPages="3" translatesAutoresizingMaskIntoConstraints="NO" id="lOm-CZ-dVG"> 126 <pageControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" numberOfPages="3" translatesAutoresizingMaskIntoConstraints="NO" id="lOm-CZ-dVG">
127 - <rect key="frame" x="170" y="424" width="73" height="26"/> 127 + <rect key="frame" x="170" y="439" width="73" height="26"/>
128 </pageControl> 128 </pageControl>
129 </subviews> 129 </subviews>
130 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> 130 <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
...@@ -136,7 +136,7 @@ ...@@ -136,7 +136,7 @@
136 <constraint firstAttribute="trailing" secondItem="JTs-J5-DO2" secondAttribute="trailing" constant="24" id="Rdi-FK-2Ft"/> 136 <constraint firstAttribute="trailing" secondItem="JTs-J5-DO2" secondAttribute="trailing" constant="24" id="Rdi-FK-2Ft"/>
137 <constraint firstAttribute="trailing" secondItem="I7z-Fz-SNP" secondAttribute="trailing" id="avB-Gc-ttI"/> 137 <constraint firstAttribute="trailing" secondItem="I7z-Fz-SNP" secondAttribute="trailing" id="avB-Gc-ttI"/>
138 <constraint firstItem="I7z-Fz-SNP" firstAttribute="leading" secondItem="VzF-dQ-3Wa" secondAttribute="leading" id="pTY-7d-s1S"/> 138 <constraint firstItem="I7z-Fz-SNP" firstAttribute="leading" secondItem="VzF-dQ-3Wa" secondAttribute="leading" id="pTY-7d-s1S"/>
139 - <constraint firstItem="I7z-Fz-SNP" firstAttribute="top" secondItem="JTs-J5-DO2" secondAttribute="bottom" constant="5" id="vJF-jy-p83"/> 139 + <constraint firstItem="I7z-Fz-SNP" firstAttribute="top" secondItem="JTs-J5-DO2" secondAttribute="bottom" constant="20" id="vJF-jy-p83"/>
140 <constraint firstItem="lOm-CZ-dVG" firstAttribute="centerX" secondItem="VzF-dQ-3Wa" secondAttribute="centerX" id="xpw-tV-NcW"/> 140 <constraint firstItem="lOm-CZ-dVG" firstAttribute="centerX" secondItem="VzF-dQ-3Wa" secondAttribute="centerX" id="xpw-tV-NcW"/>
141 </constraints> 141 </constraints>
142 </view> 142 </view>
......