MyRewardsBannerOffersScrollTableViewCell.swift
4.89 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//
// MyRewardsBannerOffersScrollTableViewCell.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 23/5/25.
//
import UIKit
@objc public class MyRewardsBannerOffersScrollTableViewCell: UITableViewCell {
@IBOutlet weak var tagView1: UIView!
@IBOutlet weak var tagLabel1: UILabel!
@IBOutlet weak var tagView2: UIView!
@IBOutlet weak var tagLabel2: UILabel!
@IBOutlet weak var profileImage: UIImageView!
@IBOutlet weak var collectionView: UICollectionView!
var data: SectionModel?
public override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
profileImage.image = UIImage(named: "profile_pic_default", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
tagView1.backgroundColor = UIColor(rgb: 0x09914E)
tagView1.layer.cornerRadius = 4.0
tagLabel1.font = UIFont(name: "PingLCG-Regular", size: 17)
tagLabel1.textColor = UIColor(rgb: 0xFFFFFF)
tagView2.backgroundColor = UIColor(rgb: 0xFC9F25)
tagView2.layer.cornerRadius = 4.0
tagLabel2.font = UIFont(name: "PingLCG-Regular", size: 17)
tagLabel2.textColor = UIColor(rgb: 0xFFFFFF)
// Register XIBs for collection view cells
collectionView.register(UINib(nibName: "MyRewardsBannerOfferCollectionViewCell", bundle: Bundle(for: MyEmptyClass.self)), forCellWithReuseIdentifier: "MyRewardsBannerOfferCollectionViewCell")
// Fix background colors
collectionView.backgroundColor = UIColor.clear
self.backgroundColor = UIColor.clear
self.contentView.backgroundColor = UIColor.clear
// Remove content insets and gaps
collectionView.contentInset = UIEdgeInsets.zero
collectionView.scrollIndicatorInsets = UIEdgeInsets.zero
if #available(iOS 11.0, *) {
collectionView.contentInsetAdjustmentBehavior = .never
}
// Configure collection view layout
if let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
layout.scrollDirection = .horizontal
layout.minimumLineSpacing = 0
layout.minimumInteritemSpacing = 0
layout.sectionInset = UIEdgeInsets.zero
}
// Enable paging for smooth banner scrolling
collectionView.isPagingEnabled = true
collectionView.showsHorizontalScrollIndicator = false
// Set delegates
collectionView.delegate = self
collectionView.dataSource = self
}
public override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func configureCell(data: SectionModel?) {
self.data = data
self.collectionView.reloadData();
}
}
extension MyRewardsBannerOffersScrollTableViewCell: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
public func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.data?.offers.count ?? 0
}
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MyRewardsBannerOfferCollectionViewCell", for: indexPath) as! MyRewardsBannerOfferCollectionViewCell
// cell.configureCell(offer: self.data?.offers[indexPath.row])
if let offer = self.data?.offers[indexPath.row] {
cell.configureCell(data: offer)
}
return cell;
}
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// TODO: open offer
}
// MARK: - UICollectionViewDelegateFlowLayout
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let screenWidth = UIScreen.main.bounds.width
return CGSize(width: screenWidth, height: 348)
}
// Distance Between Item Cells
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
// Cell Margin
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets.zero
}
}