WallPaperHome722/WallpaperHD_Live/Mine/C/WP_CollectionVC.swift
2024-07-25 19:20:41 +08:00

77 lines
2.4 KiB
Swift

//
// WP_CollectionVC.swift
// WallpaperHD_Live
//
// Created by 16 on 2024/7/22.
//
import UIKit
class WP_CollectionVC: WP_RootVC {
@IBOutlet weak var dataView: UIView!
@IBOutlet weak var collectionView: UICollectionView!
var imageName = [String]()
override func viewDidLoad() {
super.viewDidLoad()
setCollectionView()
}
func setCollectionView(){
collectionView.delegate = self
collectionView.dataSource = self
// collection view
let layout = CustomCollectionViewFlowLayout()
collectionView.collectionViewLayout = layout
layout.scrollDirection = .vertical
collectionView.register(UINib(nibName: "WP_WallpaperCollectionCell", bundle: nil), forCellWithReuseIdentifier: "WP_WallpaperCollectionCell")
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.navigationBar.isHidden = true
let manager = ImageNameManager()
self.imageName = manager.getImageNames()
print(imageName) //
if self.imageName.count == 0{
self.dataView.isHidden = false
}else{
self.dataView.isHidden = true
}
}
@IBAction func back(_ sender: Any) {
self.navigationController?.popViewController(animated: true)
}
}
extension WP_CollectionVC:UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return imageName.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "WP_WallpaperCollectionCell", for: indexPath)as!WP_WallpaperCollectionCell
// if
cell.wpImagV.image = UIImage(named: self.imageName[indexPath.row])
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let vc = WP_WallPaPerDetailsVC()
vc.imageName = self.imageName[indexPath.row]
navigationController?.pushViewController(vc, animated: true)
}
}