prank/Funny_sounds/Home/C/FS_ClassificationVC.swift
2024-09-03 09:38:34 +08:00

151 lines
4.5 KiB
Swift

//
// FS_ClassificationVC.swift
// Funny_sounds
//
// Created by 16 on 2024/8/15.
//
import UIKit
import SnapKit
class FS_ClassificationVC: RootVC {
var categoryarr = [SoundCategory]()
var arr: [AudioFile] = []
lazy var collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.backgroundColor = .clear
collectionView.showsVerticalScrollIndicator = false
return collectionView
}()
lazy var bgimage = UIImageView()
lazy var backBtn = UIButton()
lazy var titLabel = UILabel()
var typestring:String = "no hase string"
override func viewDidLoad() {
super.viewDidLoad()
setHomeUI()
setcollectionView()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.isHidden = true
}
// MARK: -
func setHomeUI(){
bgimage.image = UIImage(named: "classificationbg")
bgimage.contentMode = .scaleAspectFill
self.view.addSubview(bgimage)
backBtn.setImage(UIImage(named: "back"), for: .normal)
backBtn.addTarget(self, action: #selector(back), for: .touchUpInside)
self.view.addSubview(backBtn)
titLabel.text = typestring
titLabel.font = UIFont(name: "PaytoneOne-Regular", size: 25)
titLabel.textColor = .white
titLabel.numberOfLines = 1
titLabel.textAlignment = .center
self.view.addSubview(titLabel)
collectionView.backgroundColor = .clear
collectionView.showsVerticalScrollIndicator = false
self.view.addSubview(collectionView)
bgimage.snp.makeConstraints { make in
make.width.equalTo(self.view)
make.height.equalTo(self.view)
}
backBtn.snp.makeConstraints { make in
make.top.equalTo(self.view.safeAreaLayoutGuide).offset(20)
make.height.width.equalTo(36)
make.left.equalToSuperview().offset(20)
}
titLabel.snp.makeConstraints { make in
make.centerY.equalTo(backBtn).offset(-2)
make.centerX.equalToSuperview()
make.left.equalTo(backBtn.snp.right).offset(5)
make.right.equalToSuperview().offset(10)
}
collectionView.snp.makeConstraints { make in
make.top.equalTo(titLabel.snp.bottom).offset(25)
make.width.equalToSuperview()
make.bottom.equalTo(self.view.safeAreaLayoutGuide)
}
}
// MARK: -collectionView
func setcollectionView(){
collectionView.delegate = self
collectionView.dataSource = self
let layout = tyepeCollectionViewFlowLayout()
collectionView.collectionViewLayout = layout
layout.scrollDirection = .vertical
collectionView.register(FS_ClassificationCollectionCell.self, forCellWithReuseIdentifier: "FS_ClassificationCollectionCell")
}
@objc func back(){
self.navigationController?.popViewController(animated: true)
}
}
// MARK: -collectionView
extension FS_ClassificationVC:UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return arr.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FS_ClassificationCollectionCell", for: indexPath)as!FS_ClassificationCollectionCell
cell.model = arr[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath){
let vc = FS_DetailsVC()
vc.arr = self.arr
vc.model = self.arr[indexPath.row]
navigationController?.pushViewController(vc, animated: true)
}
}