fix
杨锴
2024-08-23 adc2db9bb29e7f316c46b6de679db1522ffc9cc8
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
//
//  VIPCenterVC.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/15.
//
 
import UIKit
import JQTools
 
class VIPCenterVC: BaseVC {
 
                @IBOutlet weak var collectionView: UICollectionView!
                private var selectIndex = 0
 
                override func viewDidLoad() {
        super.viewDidLoad()
                                title = "会员中心"
 
                                collectionView.delegate = self
                                collectionView.dataSource = self
                                collectionView.showsHorizontalScrollIndicator = false
                                collectionView.contentInset = UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 15)
                                collectionView.register(VipCenterCCell.self, forCellWithReuseIdentifier: "cell")
    }
}
 
extension VIPCenterVC:UICollectionViewDelegate & UICollectionViewDataSource{
 
                func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
                                selectIndex = indexPath.row
                                collectionView.reloadData()
                }
 
                func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! VipCenterCCell
                                cell.isSelect(indexPath.row == selectIndex)
                                return cell
                }
 
                func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                                return 5
                }
}
 
extension VIPCenterVC:UICollectionViewDelegateFlowLayout{
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
                                return CGSize(width: 111, height: 132)
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
                                return 11.5
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
                                return 11.5
                }
}
 
class VipCenterCCell:UICollectionViewCell{
 
                private var label_title:UILabel!
                private var label_price:UILabel!
                private var lable_priorDay:UILabel!
 
                override init(frame: CGRect) {
                                super.init(frame: frame)
                                contentView.jq_cornerRadius = 10
                                contentView.backgroundColor = UIColor(hexString: "#EFF2F2")
                                setUI()
                }
 
 
                func setUI(){
                                label_title  = UILabel()
                                label_title.text = "年度会员"
                                label_title.textAlignment = .center
                                label_title.textColor = UIColor(hexString: "#353535")
                                label_title.font = .systemFont(ofSize: 16, weight: .medium)
                                contentView.addSubview(label_title)
                                label_title.snp.makeConstraints { make in
                                                make.top.equalTo(31)
                                                make.centerX.equalToSuperview()
                                                make.height.equalTo(15)
                                }
 
                                label_price  = UILabel()
                                label_price.attributedText = AttributedStringbuilder.build().add(string: "¥", withFont: .systemFont(ofSize: 15, weight:.heavy), withColor: UIColor(hexString: "#353535")!).add(string: "199", withFont: .systemFont(ofSize: 20, weight:.heavy), withColor: UIColor(hexString: "#353535")!).mutableAttributedString
                                label_price.textAlignment = .center
                                label_price.font = .systemFont(ofSize: 16, weight: .medium)
                                contentView.addSubview(label_price)
                                label_price.snp.makeConstraints { make in
                                                make.top.equalTo(label_title.snp.bottom).offset(15.5)
                                                make.centerX.equalToSuperview()
                                                make.height.equalTo(15)
                                }
 
                                lable_priorDay  = UILabel()
                                lable_priorDay.text = "¥0/天"
                                lable_priorDay.textAlignment = .center
                                lable_priorDay.font = .systemFont(ofSize: 11, weight: .medium)
                                contentView.addSubview(lable_priorDay)
                                lable_priorDay.snp.makeConstraints { make in
                                                make.top.equalTo(label_price.snp.bottom).offset(15.5)
                                                make.centerX.equalToSuperview()
                                                make.height.equalTo(15)
                                }
                }
 
                func isSelect(_ state:Bool){
                                if state{
                                                contentView.backgroundColor = UIColor(hexString: "#A6C586")
                                                label_title.textColor = .white
                                                lable_priorDay.textColor = .white
                                                label_price.attributedText = AttributedStringbuilder.build().add(string: "¥", withFont: .systemFont(ofSize: 15, weight:.heavy), withColor: .white).add(string: "199", withFont: .systemFont(ofSize: 20, weight:.heavy), withColor: .white).mutableAttributedString
                                }else{
                                                contentView.backgroundColor = UIColor(hexString: "#EFF2F2")
                                                label_title.textColor = UIColor(hexString: "#353535")
                                                lable_priorDay.textColor = UIColor(hexString: "#B7B7B7")
                                                label_price.attributedText = AttributedStringbuilder.build().add(string: "¥", withFont: .systemFont(ofSize: 15, weight:.heavy), withColor: UIColor(hexString: "#353535")!).add(string: "199", withFont: .systemFont(ofSize: 20, weight:.heavy), withColor: UIColor(hexString: "#353535")!).mutableAttributedString
                                }
                }
 
                required init?(coder: NSCoder) {
                                fatalError("init(coder:) has not been implemented")
                }
}