MerchantTableViewCell.swift
3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// MerchantTableViewCell.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 18/10/24.
//
import UIKit
// Define a protocol (if using delegation)
protocol MerchantTableViewCellDelegate: AnyObject {
func didTapButton(in cell: MerchantTableViewCell)
}
class MerchantTableViewCell: UITableViewCell {
@IBOutlet weak var mainView: UIView!
@IBOutlet weak var merchantImage: UIImageView!
@IBOutlet weak var buttonView: UIView!
@IBOutlet weak var buttonTitleLable: UILabel!
@IBOutlet weak var buttonIconImage: UIImageView!
@IBOutlet weak var actionButton: UIButton!
// Delegate variable
weak var delegate: MerchantTableViewCellDelegate?
let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
var postImageURL: String? {
didSet {
if let url = postImageURL {
self.merchantImage.image = UIImage() // UIImage(named: "loading")
UIImage.loadImageUsingCacheWithUrlString(url) { image in
// set the image only when we are still displaying the content for the image we finished downloading
if url == self.postImageURL {
self.merchantImage.image = image
}
}
}
else {
self.merchantImage.image = nil
}
}
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
mainView.backgroundColor = UIColor(rgb: 0xF2F2F3)
mainView.layer.cornerRadius = 20.0
buttonTitleLable.font = UIFont(name: "PeridotPE-SBold", size: 13)
buttonTitleLable.textColor = UIColor(rgb: 0xFFFFFF)
buttonView.backgroundColor = UIColor(rgb: 0x0EA600)
buttonView.layer.cornerRadius = 12.0
// Add action for button tap
actionButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
public override func layoutSubviews() {
super.layoutSubviews()
//set the values for top,left,bottom,right margins
let margins = UIEdgeInsets(top: 0, left: 0, bottom: 32, right: 0)
contentView.frame = contentView.frame.inset(by: margins)
}
func configureCell(shop: swiftApi.ShopAvailabilityItemModel, buttonTitle: String, iconImage: String?, showEshops: Bool?) {
if (showEshops == true) {
if (shop._merchant_uuid == "ab") {
self.merchantImage.image = UIImage(named: "eshop_ab", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
} else if (shop._merchant_uuid == "masoutis") {
self.merchantImage.image = UIImage(named: "eshop_masoutis", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
}
} else {
for merchant in merchantList {
if (merchant._uuid == shop._merchant_uuid) {
self.postImageURL = merchant._img_preview
break;
}
}
}
buttonTitleLable.text = buttonTitle
if let iconImage {
self.buttonIconImage.image = UIImage(named: iconImage, in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
self.buttonIconImage.isHidden = false
} else {
self.buttonIconImage.isHidden = true
}
}
@objc private func buttonTapped() {
// Notify the delegate when button is tapped
delegate?.didTapButton(in: self)
}
}