201 lines
6.3 KiB
Swift
201 lines
6.3 KiB
Swift
|
|
import Foundation
|
|
|
|
import UIKit
|
|
import SnapKit
|
|
|
|
|
|
extension ZAvoritesView {
|
|
|
|
class YQNewsView: UIView {
|
|
private var heteromorphic_padding: Double? = 0.0
|
|
private var popThimra_dict: [String: Any]?
|
|
var config_padding: Double? = 0.0
|
|
|
|
|
|
|
|
var didSelectedShort: ((_ model: MTypeAvgation?) -> Void)?
|
|
|
|
var dataArr: [MTypeAvgation]? {
|
|
didSet {
|
|
self.collectionView.reloadData()
|
|
}
|
|
}
|
|
|
|
lazy var bgImageView = UIImageView()
|
|
|
|
lazy var trophyImageView = UIImageView(image: UIImage(named: "rightCheck"))
|
|
|
|
lazy var titleLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .font(ofSize: 15, weight: .bold)
|
|
label.textColor = .white
|
|
return label
|
|
}()
|
|
|
|
lazy var collectionViewLayout: UICollectionViewFlowLayout = {
|
|
let layout = UICollectionViewFlowLayout()
|
|
layout.itemSize = .init(width: 198, height: 53)
|
|
layout.minimumLineSpacing = 9
|
|
return layout
|
|
}()
|
|
|
|
lazy var collectionView: ZWContentAvigationView = {
|
|
let collectionView = ZWContentAvigationView(frame: .zero, collectionViewLayout: collectionViewLayout)
|
|
collectionView.delegate = self
|
|
collectionView.dataSource = self
|
|
collectionView.isScrollEnabled = false
|
|
collectionView.register(GUnechoEditCell.self, forCellWithReuseIdentifier: "cell")
|
|
return collectionView
|
|
}()
|
|
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
bgImageView.isUserInteractionEnabled = true
|
|
|
|
addSubview(bgImageView)
|
|
addSubview(trophyImageView)
|
|
bgImageView.addSubview(titleLabel)
|
|
bgImageView.addSubview(collectionView)
|
|
|
|
bgImageView.snp.makeConstraints { make in
|
|
make.left.right.bottom.equalToSuperview()
|
|
make.top.equalToSuperview().offset(16)
|
|
make.width.equalTo(198)
|
|
}
|
|
|
|
trophyImageView.snp.makeConstraints { make in
|
|
make.top.right.equalToSuperview()
|
|
}
|
|
|
|
titleLabel.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(10)
|
|
make.top.equalToSuperview().offset(13)
|
|
}
|
|
|
|
collectionView.snp.makeConstraints { make in
|
|
make.left.equalToSuperview()
|
|
make.right.equalToSuperview()
|
|
make.top.equalToSuperview().offset(46)
|
|
make.bottom.equalToSuperview()
|
|
}
|
|
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
extension ZAvoritesView.YQNewsView: UICollectionViewDelegate, UICollectionViewDataSource {
|
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return min(3, self.dataArr?.count ?? 0)
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! ZAvoritesView.GUnechoEditCell
|
|
cell.row = indexPath.row
|
|
cell.model = self.dataArr?[indexPath.row]
|
|
return cell
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
self.didSelectedShort?(self.dataArr?[indexPath.row])
|
|
}
|
|
|
|
}
|
|
|
|
|
|
extension ZAvoritesView {
|
|
class GUnechoEditCell: UICollectionViewCell {
|
|
var hortSceneMap: [String: Any]!
|
|
private var startPadding: Double? = 0.0
|
|
|
|
|
|
|
|
|
|
var model: MTypeAvgation? {
|
|
didSet {
|
|
coverImageView.sr_setImage(model?.image_url)
|
|
titleLabel.text = model?.name
|
|
hotView.count = model?.watch_total ?? 0
|
|
}
|
|
}
|
|
|
|
var row: Int = 0 {
|
|
didSet {
|
|
numLabel.text = "\(row + 1)"
|
|
}
|
|
}
|
|
|
|
lazy var numLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .font(ofSize: 12, weight: .bold)
|
|
label.textColor = .white
|
|
return label
|
|
}()
|
|
|
|
lazy var coverImageView: TPRegisterView = {
|
|
let imageView = TPRegisterView()
|
|
imageView.layer.cornerRadius = 2
|
|
imageView.layer.masksToBounds = true
|
|
return imageView
|
|
}()
|
|
|
|
lazy var titleLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .font(ofSize: 12, weight: .medium)
|
|
label.textColor = .white
|
|
return label
|
|
}()
|
|
|
|
lazy var hotView: NXLoginElarisView = {
|
|
let view = NXLoginElarisView()
|
|
return view
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
|
|
contentView.addSubview(numLabel)
|
|
contentView.addSubview(coverImageView)
|
|
contentView.addSubview(titleLabel)
|
|
contentView.addSubview(hotView)
|
|
|
|
numLabel.snp.makeConstraints { make in
|
|
make.centerY.equalToSuperview()
|
|
make.centerX.equalTo(self.contentView.snp.left).offset(14)
|
|
}
|
|
|
|
coverImageView.snp.makeConstraints { make in
|
|
make.top.bottom.equalToSuperview()
|
|
make.left.equalToSuperview().offset(24)
|
|
make.width.equalTo(40)
|
|
}
|
|
|
|
titleLabel.snp.makeConstraints { make in
|
|
make.top.equalToSuperview().offset(10)
|
|
make.left.equalTo(coverImageView.snp.right).offset(6)
|
|
make.right.lessThanOrEqualToSuperview().offset(-9)
|
|
}
|
|
|
|
hotView.snp.makeConstraints { make in
|
|
make.left.equalTo(coverImageView.snp.right).offset(6)
|
|
make.bottom.equalToSuperview().offset(-7)
|
|
}
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
}
|
|
}
|
|
|