杨锴
2024-08-14 909e20941e45f8712c012db602034b47da0bfdb0
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
//
//  HomeItemListVC.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/14.
//
 
import UIKit
import JQTools
 
class HomeItemViewModel:RefreshModel<SimpleModel>{
 
}
 
 
class HomeItemListVC: BaseVC {
 
                private var collectionView:UICollectionView!
                private var topTitle:String!
                private var id:Int!
 
                private var viewModel = HomeItemViewModel()
 
                init(topTitle:String,id:Int) {
                                super.init(nibName: nil, bundle: nil)
                                self.topTitle = topTitle
                                self.id = id
                }
 
    override func viewDidLoad() {
        super.viewDidLoad()
                                title = self.topTitle
 
                                viewModel.configure(collectionView)
    }
 
                override func setUI() {
                                view.backgroundColor = UIColor(hexString: "#f6f6f6")
                                let layout = UICollectionViewFlowLayout()
                                 let w = (JQ_ScreenW - 21.5 * 2 - 13.5) / 2
                                let h = w * 1.3142
                                layout.itemSize = CGSize(width: w, height: h)
                                layout.minimumLineSpacing = 13.5
                                layout.minimumInteritemSpacing = 13.5
                                layout.headerReferenceSize = CGSize(width: JQ_ScreenW, height: 20)
                                collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
                                collectionView.delegate = self
                                collectionView.dataSource = self
                                collectionView.backgroundColor = UIColor(hexString: "#f6f6f6")
                                collectionView.contentInset = UIEdgeInsets(top: 0, left: 21.5, bottom: 0, right: 21.5)
                                collectionView.register(UINib(nibName: "HomeRelaxBanner_2_CCell", bundle: nil), forCellWithReuseIdentifier: "_HomeRelaxBanner_2_CCell")
                                view.addSubview(collectionView)
                                collectionView.snp.makeConstraints { make in
                                                make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(0)
                                                make.right.bottom.left.equalToSuperview()
                                }
                }
 
                required init?(coder: NSCoder) {
                                fatalError("init(coder:) has not been implemented")
                }
}
 
extension HomeItemListVC:UICollectionViewDelegate & UICollectionViewDataSource{
                func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_CCell", for: indexPath) as! HomeRelaxBanner_2_CCell
                                cell.backgroundColor = .jq_randomColor
                                return cell
                }
 
                func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                                return 50
                }
 
                func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
                                let vc = HomeItemDetailVC()
                                push(vc: vc)
                }
}