Wallpaper_Home/wallpaper_project/Home/C/NewHome/V/WA_MonRankngCell.swift
忆海16 5ff1070967 mtg
2024-07-23 11:44:01 +08:00

105 lines
3.8 KiB
Swift

//
// WA_MonRankngCell.swift
// wallpaper_project
import UIKit
class WA_MonRankngCell: UITableViewCell {
@IBOutlet weak var collectionView: UICollectionView!
let cellWidth: CGFloat = 150
let cellHeight: CGFloat = 300
let cellSpacing: CGFloat = 10
var TexturesWallpapers: [WallpaperData] = []
var jpgblock:(()->())?
override func awakeFromNib() {
super.awakeFromNib()
setcollectionV()
settypeNetwork()
}
func setcollectionV(){
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
collectionView.dataSource = self
collectionView.delegate = self
collectionView.collectionViewLayout = layout
collectionView.register(UINib(nibName: "WA_ToDayCollectCell", bundle: nil), forCellWithReuseIdentifier: "WA_ToDayCollectCell")
}
func settypeNetwork(){
// JSON
guard let jsonFilePath = Bundle.main.path(forResource: "my_wallpaper", ofType: "json") else {
fatalError("Unable to locate my_wallpaper.json file.")
}
// JSON
do {
// JSON
let jsonData = try Data(contentsOf: URL(fileURLWithPath: jsonFilePath))
// JSON Swift
let decoder = JSONDecoder()
let wallpaperModels = try decoder.decode([WallpaperModel].self, from: jsonData)
// WallpaperModel
for wallpaperModel in wallpaperModels {
//
switch wallpaperModel.name {
case "High quality wallpapers":
TexturesWallpapers = wallpaperModel.data
default:
break
}
}
} catch {
print("Error reading or parsing JSON file: \(error)")
}
}
}
extension WA_MonRankngCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UICollectionViewDelegate{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "WA_ToDayCollectCell", for: indexPath) as! WA_ToDayCollectCell
cell.model = self.TexturesWallpapers[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: cellWidth, height: cellHeight)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return cellSpacing
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 0, left: cellSpacing, bottom: 0, right: cellSpacing)
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let topViewController = UIApplication.getTopViewController() {
//
let vc = WA_DetailsVC()
vc.type = 2
vc.modeltype = self.TexturesWallpapers[indexPath.row]
//
topViewController.navigationController?.pushViewController(vc, animated: true)
}
}
}