82 lines
2.4 KiB
Swift
82 lines
2.4 KiB
Swift
//
|
|
// SPHomeShortsForYouView.swift
|
|
// ShortPlay
|
|
//
|
|
// Created by 曾觉新 on 2025/4/14.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class SPHomeShortsForYouView: SPHomeDataItemView {
|
|
|
|
|
|
override class func contentHeight(dataArr: [SPShortModel]) -> CGFloat {
|
|
return 271 + contentToTop
|
|
}
|
|
|
|
override var dataArr: [SPShortModel]? {
|
|
didSet {
|
|
self.collectionView.reloadData()
|
|
}
|
|
}
|
|
|
|
|
|
private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
|
|
let layout = UICollectionViewFlowLayout()
|
|
layout.scrollDirection = .horizontal
|
|
layout.itemSize = CGSize(width: 204, height: 271)
|
|
layout.sectionInset = UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 15)
|
|
layout.minimumLineSpacing = 15
|
|
layout.minimumInteritemSpacing = 15
|
|
return layout
|
|
}()
|
|
|
|
private lazy var collectionView: SPCollectionView = {
|
|
let collectionView = SPCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
|
|
collectionView.delegate = self
|
|
collectionView.dataSource = self
|
|
collectionView.showsVerticalScrollIndicator = false
|
|
collectionView.showsHorizontalScrollIndicator = false
|
|
SPHomeShortsForYouCell.registerCell(collectionView: collectionView)
|
|
return collectionView
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
self.titleLabel.text = "Shorts for You".localized
|
|
|
|
_setupUI()
|
|
}
|
|
|
|
@MainActor required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
}
|
|
|
|
extension SPHomeShortsForYouView {
|
|
|
|
private func _setupUI() {
|
|
contentView.addSubview(collectionView)
|
|
|
|
collectionView.snp.makeConstraints { make in
|
|
make.edges.equalToSuperview()
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//MARK: -------------- UICollectionViewDelegate & UICollectionViewDataSource --------------
|
|
extension SPHomeShortsForYouView: UICollectionViewDelegate, UICollectionViewDataSource {
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
let cell = SPHomeShortsForYouCell.dequeueReusableCell(collectionView: collectionView, indexPath: indexPath)
|
|
return cell
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return dataArr?.count ?? 0
|
|
}
|
|
|
|
}
|