Showing
6 changed files
with
108 additions
and
5 deletions
... | @@ -7,7 +7,7 @@ | ... | @@ -7,7 +7,7 @@ |
7 | <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key> | 7 | <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key> |
8 | <dict> | 8 | <dict> |
9 | <key>orderHint</key> | 9 | <key>orderHint</key> |
10 | - <integer>1</integer> | 10 | + <integer>0</integer> |
11 | </dict> | 11 | </dict> |
12 | </dict> | 12 | </dict> |
13 | </dict> | 13 | </dict> | ... | ... |
... | @@ -7,7 +7,7 @@ | ... | @@ -7,7 +7,7 @@ |
7 | <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key> | 7 | <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key> |
8 | <dict> | 8 | <dict> |
9 | <key>orderHint</key> | 9 | <key>orderHint</key> |
10 | - <integer>0</integer> | 10 | + <integer>1</integer> |
11 | </dict> | 11 | </dict> |
12 | </dict> | 12 | </dict> |
13 | </dict> | 13 | </dict> | ... | ... |
No preview for this file type
... | @@ -20,12 +20,32 @@ import UIKit | ... | @@ -20,12 +20,32 @@ import UIKit |
20 | @IBOutlet weak var expirationRedImage: UIImageView! | 20 | @IBOutlet weak var expirationRedImage: UIImageView! |
21 | @IBOutlet weak var expirationRedLabel: UILabel! | 21 | @IBOutlet weak var expirationRedLabel: UILabel! |
22 | 22 | ||
23 | + | ||
24 | + // Variables for the view, image, and button | ||
25 | + var selectView: UIView! | ||
26 | + var selectImageView: UIImageView! | ||
27 | + var selectButton: UIButton! | ||
28 | + | ||
29 | + // Boolean to track if the selectView should be visible | ||
30 | + var isSelectViewVisible: Bool = false { | ||
31 | + didSet { | ||
32 | + selectView.isHidden = !isSelectViewVisible | ||
33 | + } | ||
34 | + } | ||
35 | + | ||
36 | + // Boolean to track the selection state of the cell | ||
37 | + var isSelectedCell: Bool = false { | ||
38 | + didSet { | ||
39 | + updateSelectionState() | ||
40 | + } | ||
41 | + } | ||
42 | + | ||
43 | + // Action closure for button tap inside the cell | ||
44 | + var selectButtonAction: (() -> Void)? | ||
45 | + | ||
23 | var postImageURL: String? { | 46 | var postImageURL: String? { |
24 | didSet { | 47 | didSet { |
25 | if let url = postImageURL { | 48 | if let url = postImageURL { |
26 | - // TODO: DELETE LOGS | ||
27 | - print("=== postImageURL: ",url) | ||
28 | - | ||
29 | self.couponImage.image = UIImage() // UIImage(named: "loading") | 49 | self.couponImage.image = UIImage() // UIImage(named: "loading") |
30 | 50 | ||
31 | UIImage.loadImageUsingCacheWithUrlString(url) { image in | 51 | UIImage.loadImageUsingCacheWithUrlString(url) { image in |
... | @@ -49,6 +69,8 @@ import UIKit | ... | @@ -49,6 +69,8 @@ import UIKit |
49 | couponBgImage.image = UIImage(named: "coupon_bg_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) | 69 | couponBgImage.image = UIImage(named: "coupon_bg_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) |
50 | 70 | ||
51 | borderView.addDashedBorderVertical(color: UIColor(red: 0.62, green: 0.62, blue: 0.61, alpha: 1.00), width: 1.0, height: 110.0) | 71 | borderView.addDashedBorderVertical(color: UIColor(red: 0.62, green: 0.62, blue: 0.61, alpha: 1.00), width: 1.0, height: 110.0) |
72 | + | ||
73 | + setupSelectButton() | ||
52 | } | 74 | } |
53 | 75 | ||
54 | public override func setSelected(_ selected: Bool, animated: Bool) { | 76 | public override func setSelected(_ selected: Bool, animated: Bool) { |
... | @@ -64,6 +86,69 @@ import UIKit | ... | @@ -64,6 +86,69 @@ import UIKit |
64 | contentView.frame = contentView.frame.inset(by: margins) | 86 | contentView.frame = contentView.frame.inset(by: margins) |
65 | } | 87 | } |
66 | 88 | ||
89 | + // Setup Select Button UI and layout | ||
90 | + func setupSelectButton() { | ||
91 | + // Create the container view (selectView) | ||
92 | + selectView = UIView() | ||
93 | + selectView.translatesAutoresizingMaskIntoConstraints = false | ||
94 | + contentView.addSubview(selectView) | ||
95 | + | ||
96 | + // Set selectView constraints | ||
97 | + NSLayoutConstraint.activate([ | ||
98 | + selectView.widthAnchor.constraint(equalToConstant: 26), | ||
99 | + selectView.heightAnchor.constraint(equalToConstant: 26), | ||
100 | + selectView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 6), | ||
101 | + selectView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16) | ||
102 | + ]) | ||
103 | + | ||
104 | + // Create the UIImageView inside selectView | ||
105 | + selectImageView = UIImageView() | ||
106 | + selectImageView.contentMode = .scaleAspectFit | ||
107 | + selectImageView.translatesAutoresizingMaskIntoConstraints = false | ||
108 | + selectView.addSubview(selectImageView) | ||
109 | + | ||
110 | + // Set imageView constraints to match the size of the selectView | ||
111 | + NSLayoutConstraint.activate([ | ||
112 | + selectImageView.leadingAnchor.constraint(equalTo: selectView.leadingAnchor), | ||
113 | + selectImageView.trailingAnchor.constraint(equalTo: selectView.trailingAnchor), | ||
114 | + selectImageView.topAnchor.constraint(equalTo: selectView.topAnchor), | ||
115 | + selectImageView.bottomAnchor.constraint(equalTo: selectView.bottomAnchor) | ||
116 | + ]) | ||
117 | + | ||
118 | + // Create the transparent button on top of the imageView | ||
119 | + selectButton = UIButton(type: .custom) | ||
120 | + selectButton.backgroundColor = .clear // Make the button transparent | ||
121 | + selectButton.translatesAutoresizingMaskIntoConstraints = false | ||
122 | + selectButton.addTarget(self, action: #selector(selectButtonTapped), for: .touchUpInside) | ||
123 | + selectView.addSubview(selectButton) | ||
124 | + | ||
125 | + // Set button constraints to match the size of the selectView | ||
126 | + NSLayoutConstraint.activate([ | ||
127 | + selectButton.leadingAnchor.constraint(equalTo: selectView.leadingAnchor), | ||
128 | + selectButton.trailingAnchor.constraint(equalTo: selectView.trailingAnchor), | ||
129 | + selectButton.topAnchor.constraint(equalTo: selectView.topAnchor), | ||
130 | + selectButton.bottomAnchor.constraint(equalTo: selectView.bottomAnchor) | ||
131 | + ]) | ||
132 | + | ||
133 | + // Initially hide the selectView (selectView) | ||
134 | + selectView.isHidden = true | ||
135 | + } | ||
136 | + | ||
137 | + // Button action handler | ||
138 | + @objc func selectButtonTapped() { | ||
139 | + // Trigger the action closure when the button is pressed | ||
140 | + selectButtonAction?() | ||
141 | + } | ||
142 | + | ||
143 | + // Update the cell's appearance based on selection state | ||
144 | + func updateSelectionState() { | ||
145 | + // Update the image based on the new state | ||
146 | + if (isSelectedCell) { | ||
147 | + selectImageView.image = UIImage(named: "circle_checked", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) // Selected image | ||
148 | + } else { | ||
149 | + selectImageView.image = UIImage(named: "circle_unchecked", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) // Unselected image | ||
150 | + } | ||
151 | + } | ||
67 | 152 | ||
68 | func configureCell(coupon: swiftApi.CouponItemModel) { | 153 | func configureCell(coupon: swiftApi.CouponItemModel) { |
69 | // COUPONSET: desc, img_preview, name, terms, merchant_uuid, discount_type, final_price | 154 | // COUPONSET: desc, img_preview, name, terms, merchant_uuid, discount_type, final_price |
... | @@ -240,4 +325,22 @@ import UIKit | ... | @@ -240,4 +325,22 @@ import UIKit |
240 | 325 | ||
241 | } | 326 | } |
242 | 327 | ||
328 | + // Configure the cell with visibility of the selectView, a selected state, and select Button Action | ||
329 | + func showSelectButton(isSelectViewVisible: Bool, isSelected: Bool, buttonAction: @escaping () -> Void) { | ||
330 | + self.isSelectViewVisible = isSelectViewVisible | ||
331 | + self.isSelectedCell = isSelected | ||
332 | + self.selectButtonAction = buttonAction | ||
333 | + | ||
334 | + if (isSelected) { | ||
335 | + couponBgImage.image = UIImage(named: "coupon_bg_2_selected", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) | ||
336 | + } else { | ||
337 | + couponBgImage.image = UIImage(named: "coupon_bg_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) | ||
338 | + } | ||
339 | + | ||
340 | + // Set nameLabel constraints to not overlap selectView | ||
341 | + NSLayoutConstraint.activate([ | ||
342 | + nameLabel.trailingAnchor.constraint(equalTo: selectView.leadingAnchor, constant: -5) | ||
343 | + ]) | ||
344 | + | ||
345 | + } | ||
243 | } | 346 | } | ... | ... |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment