//
|
// 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
|
}
|
}
|