123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- //
- // FeaturedTopicsTableViewCell.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/6/16.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- // 精选话题cell
- import UIKit
- import SwiftyMediator
- class FeaturedTopicsTableViewCell: UITableViewCell {
- class func cellWith(tableView:UITableView,indexPath:IndexPath) -> FeaturedTopicsTableViewCell {
- let ID = "FeaturedTopicsTableViewCell"
- tableView.register(FeaturedTopicsTableViewCell.self, forCellReuseIdentifier: ID)
- let cell : FeaturedTopicsTableViewCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! FeaturedTopicsTableViewCell
- cell.indexPath = indexPath
- return cell
- }
-
- override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- setupViews()
- setupLayouts()
- }
-
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- var indexPath: IndexPath? {
- didSet {
-
- }
- }
- //MRAK: - 设置View
- private func setupViews() {
- self.selectionStyle = .none
- addSubview(collectionView)
- }
-
- private func setupLayouts() {
- collectionView.snp.makeConstraints { (make) in
- make.top.left.right.bottom.equalToSuperview()
- }
- }
-
- private lazy var collectionView: UICollectionView = {
- let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
- collectionView.backgroundColor = kf7f8faColor
- collectionView.delegate = self;
- collectionView.dataSource = self;
- collectionView.showsVerticalScrollIndicator = false
- collectionView.showsHorizontalScrollIndicator = false
- return collectionView
- }()
-
- private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
- let collectionViewLayout = UICollectionViewFlowLayout.init()
- collectionViewLayout.minimumLineSpacing = 10
- collectionViewLayout.minimumInteritemSpacing = 0
- collectionViewLayout.scrollDirection = .horizontal
- return collectionViewLayout
- }()
-
- var communityRecommendTypeDataModels: Array<CommunityRecommendTypeDataModel>? {
- didSet {
- collectionView.reloadData()
- }
- }
- }
- extension FeaturedTopicsTableViewCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
- func numberOfSections(in collectionView: UICollectionView) -> Int {
-
- return communityRecommendTypeDataModels?.isEmpty ?? true ? 0 : 1
- }
-
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return communityRecommendTypeDataModels?.isEmpty ?? true ? 0 : communityRecommendTypeDataModels?.count ?? 0
- }
-
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = FeaturedTopicsCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
- cell.communityRecommendTypeDataModel = communityRecommendTypeDataModels?[indexPath.row]
- return cell
-
- }
-
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- let communityRecommendTypeDataModel = communityRecommendTypeDataModels?[indexPath.row]
- Mediator.push(CommunityRouterModuleType.pushFeaturedTopics(id: communityRecommendTypeDataModel?.id ?? 0))
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
- return CGSize(width:231, height: 163)
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
- return UIEdgeInsets(top: 0, left: 14, bottom: 10, right: 14)
- }
-
- }
|