82 lines
2.4 KiB
Swift
82 lines
2.4 KiB
Swift
//
|
|
// SRHomeYouLikeView.swift
|
|
// SynthReel
|
|
//
|
|
// Created by 澜声世纪 on 2025/11/15.
|
|
// Copyright © 2025 SR. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import SnapKit
|
|
|
|
class SRHomeYouLikeView: UIView {
|
|
|
|
var dataArr: [SRShortModel]? {
|
|
didSet {
|
|
self.collectionView.reloadData()
|
|
}
|
|
}
|
|
|
|
var didSelectedShort: ((_ model: SRShortModel?) -> Void)?
|
|
|
|
lazy var collectionViewLayout: UICollectionViewFlowLayout = {
|
|
let layout = UICollectionViewFlowLayout()
|
|
layout.scrollDirection = .horizontal
|
|
layout.minimumLineSpacing = 14
|
|
layout.itemSize = .init(width: 220, height: 82)
|
|
return layout
|
|
}()
|
|
|
|
lazy var collectionView: SRCollectionView = {
|
|
let collectionView = SRCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
|
|
collectionView.delegate = self
|
|
collectionView.dataSource = self
|
|
collectionView.showsHorizontalScrollIndicator = false
|
|
collectionView.contentInset = .init(top: 0, left: 15, bottom: 0, right: 15)
|
|
collectionView.register(SRHomeYouLikeCell.self, forCellWithReuseIdentifier: "cell")
|
|
return collectionView
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
|
|
sr_setupUI()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
}
|
|
|
|
extension SRHomeYouLikeView {
|
|
|
|
func sr_setupUI() {
|
|
|
|
addSubview(collectionView)
|
|
|
|
collectionView.snp.makeConstraints { make in
|
|
make.left.right.top.bottom.equalToSuperview()
|
|
make.height.equalTo(82)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//MARK: UICollectionViewDelegate UICollectionViewDataSource
|
|
extension SRHomeYouLikeView: UICollectionViewDelegate, UICollectionViewDataSource {
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! SRHomeYouLikeCell
|
|
cell.model = self.dataArr?[indexPath.row]
|
|
return cell
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return self.dataArr?.count ?? 0
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
self.didSelectedShort?(self.dataArr?[indexPath.row])
|
|
}
|
|
}
|