younger_times
2023-06-14 177ae5f9f619bd39e2d505709d8c5b419e7867ee
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
//
//  HomeVC.swift
//  WanPai
//
//  Created by 杨锴 on 2023/6/8.
//
 
import UIKit
 
class HomeVC: BaseVC {
 
    @IBOutlet weak var collectionView: UICollectionView!
    
    
    private var layout:WaterFallFlowLayout!
    private var items = Array<String>()
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    
    override func setUI() {
        view.backgroundColor = UIColor(hexStr: "EEF0F3")
        
        layout = WaterFallFlowLayout()
        layout.cols = 2
        layout.sectionInset = UIEdgeInsets(top: 14, left: 34, bottom: 14, right: 34)
        layout.delegate = self
        collectionView.collectionViewLayout = layout
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.register(UINib(nibName: "HomeCCell", bundle: nil), forCellWithReuseIdentifier: "_HomeCCell")
        
        for index in 1...8{
            items.append("b_\(index)")
        }
        collectionView.reloadData()
    }
    
    @IBAction func joinMemberAction(_ sender: UIButton) {
        let joinMemberVC = JoinMemberIntroduceVC()
        push(vc: joinMemberVC)
    }
    
    
    @IBAction func chooseStoresAction(_ sender: TapBtn) {
        StoresChooseView.show()
    }
    
    
    override var preferredStatusBarStyle: UIStatusBarStyle{
        return .lightContent
    }
}
 
extension HomeVC:UICollectionViewDelegate{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        if indexPath.row == 0{
            let vc = CourseListVC()
            push(vc: vc)
        }
        
        if indexPath.row == 1{
            let vc = ActivityListVC()
            push(vc: vc)
        }
    }
    
}
 
extension HomeVC:UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeCCell", for: indexPath) as! HomeCCell
        cell.img.image = UIImage(named: items[indexPath.row])
        return cell
    }
 
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return items.count
    }
    
}
 
extension HomeVC: WaterFallLayoutDelegate{
    func waterFlowLayout(_ waterFlowLayout: WaterFallFlowLayout, itemHeight indexPath: IndexPath) -> CGFloat {
        if let tempImg = UIImage(named: items[indexPath.row]){
            let radio = tempImg.size.width / tempImg.size.height
            if radio >= 0.8{
                return 185
            }else{
                return 288
            }
        }
        
        return 288
    }
}