杨锴
2024-08-21 e978b3aa02f00859588949dfdf24778b05fe4adb
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
126
127
128
129
130
//
//  StudyListVC.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/20.
//
 
import UIKit
import QMUIKit
import JQTools
 
class StudyListVC: BaseVC {
 
                @IBOutlet weak var collectionView: UICollectionView!
                override func viewDidLoad() {
        super.viewDidLoad()
                                title = "学习"
    }
 
                override func setUI() {
                                super.setUI()
                                view.backgroundColor = UIColor(hexString: "#F6F6F6")
                                collectionView.delegate = self
                                collectionView.dataSource = self
                                collectionView.backgroundColor = UIColor(hexString: "#F6F6F6")
                                collectionView.register(UINib(nibName: "EmptyCCell", bundle: nil), forCellWithReuseIdentifier: "_EmptyCCell")
                                collectionView.register(UINib(nibName: "HomeRelaxBanner_2_1_CCell", bundle: nil), forCellWithReuseIdentifier: "_HomeRelaxBanner_2_1_CCell")
                                collectionView.contentInset = UIEdgeInsets(top: 0, left: 18, bottom: 0, right: 18)
                                collectionView.register(StudyListHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header")
                }
 
                @IBAction func questionAction(_ sender: QMUIButton) {
                                let vc = HelpCenterVC()
                                push(vc: vc)
                }
}
 
extension StudyListVC:UICollectionViewDelegate & UICollectionViewDataSource{
 
                func numberOfSections(in collectionView: UICollectionView) -> Int {
                                return 2
                }
                func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                                if indexPath.section == 0{
                                            let cell    = collectionView.dequeueReusableCell(withReuseIdentifier: "_EmptyCCell", for: indexPath) as! EmptyCCell
                                                return cell
                                }
 
                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_1_CCell", for: indexPath) as! HomeRelaxBanner_2_1_CCell
                                cell.backgroundColor = .jq_randomColor
                                return cell
                }
 
                func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                                if section == 0{
                                                return 1
                                }else {
                                                return 5
                                }
                }
}
 
extension StudyListVC:UICollectionViewDelegateFlowLayout{
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
                                return 13.5
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
                                return 0
                }
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
                                return CGSize(width: JQ_ScreenW, height: 59)
                }
 
                func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
                                if kind == UICollectionView.elementKindSectionHeader{
                                                let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "header", for: indexPath) as! StudyListHeaderView
 
                                                if indexPath.section == 0{
                                                                headerView.setTitle(text: "已购课程")
                                                }else if indexPath.section == 1{
                                                                headerView.setTitle(text: "免费课程")
                                                }
                                                return headerView
                                }
 
                                return UICollectionReusableView()
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
                                if indexPath.section == 0{
                                                return CGSize(width: JQ_ScreenW, height: 279)
                                }
 
                                let w = (JQ_ScreenW - 18 * 3) / 2
                                return CGSize(width: w, height: w * 1.319)
                }
}
 
class StudyListHeaderView:UICollectionReusableView{
 
                let lineLabel = UILabel()
 
                override init(frame: CGRect) {
                                super.init(frame: frame)
                                setUI()
                }
 
 
                func setTitle(text:String){
                                lineLabel.text = text
                }
 
                required init?(coder: NSCoder) {
                                fatalError("init(coder:) has not been implemented")
                }
 
                private func setUI(){
                                backgroundColor = UIColor(hexString: "#F6F6F6")
                                lineLabel.font = .systemFont(ofSize: 15, weight: .medium)
                                lineLabel.textColor = UIColor(hexString: "#282828")
                                addSubview(lineLabel)
                                lineLabel.snp.makeConstraints { make in
                                                make.left.equalTo(0)
                                                make.centerY.equalToSuperview()
                                                make.width.equalTo(71)
                                                make.height.equalTo(20)
                                }
                }
}