PopularVideoTableViewCell.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // PopularVideoTableViewCell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/6/16.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. import SwiftyMediator
  10. class PopularVideoTableViewCell: UITableViewCell {
  11. class func cellWith(tableView:UITableView,indexPath:IndexPath) -> PopularVideoTableViewCell {
  12. let ID = "PopularVideoTableViewCell"
  13. tableView.register(PopularVideoTableViewCell.self, forCellReuseIdentifier: ID)
  14. let cell : PopularVideoTableViewCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! PopularVideoTableViewCell
  15. cell.indexPath = indexPath
  16. return cell
  17. }
  18. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  19. super.init(style: style, reuseIdentifier: reuseIdentifier)
  20. setupViews()
  21. setupLayouts()
  22. }
  23. required init?(coder aDecoder: NSCoder) {
  24. fatalError("init(coder:) has not been implemented")
  25. }
  26. var indexPath: IndexPath? {
  27. didSet {
  28. }
  29. }
  30. //MRAK: - 设置View
  31. private func setupViews() {
  32. self.selectionStyle = .none
  33. addSubview(collectionView)
  34. }
  35. private func setupLayouts() {
  36. collectionView.snp_makeConstraints { (make) in
  37. make.top.left.right.bottom.equalToSuperview()
  38. }
  39. }
  40. private lazy var collectionView: UICollectionView = {
  41. let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
  42. collectionView.backgroundColor = kf7f8faColor
  43. collectionView.delegate = self;
  44. collectionView.dataSource = self;
  45. collectionView.showsVerticalScrollIndicator = false
  46. collectionView.showsHorizontalScrollIndicator = false
  47. return collectionView
  48. }()
  49. private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
  50. let collectionViewLayout = UICollectionViewFlowLayout.init()
  51. collectionViewLayout.minimumLineSpacing = 10
  52. collectionViewLayout.minimumInteritemSpacing = 0
  53. collectionViewLayout.scrollDirection = .horizontal
  54. return collectionViewLayout
  55. }()
  56. var communityRecommendTypeDataModels: Array<CommunityRecommendTypeDataModel>? {
  57. didSet {
  58. collectionView.reloadData()
  59. }
  60. }
  61. }
  62. extension PopularVideoTableViewCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
  63. func numberOfSections(in collectionView: UICollectionView) -> Int {
  64. return communityRecommendTypeDataModels?.isEmpty ?? true ? 0 : 1
  65. }
  66. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  67. return communityRecommendTypeDataModels?.isEmpty ?? true ? 0 : communityRecommendTypeDataModels?.count ?? 0
  68. }
  69. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  70. let cell = PopularVideoCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
  71. cell.communityRecommendTypeDataModel = communityRecommendTypeDataModels?[indexPath.row]
  72. return cell
  73. }
  74. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  75. let communityRecommendTypeDataModel = communityRecommendTypeDataModels?[indexPath.row]
  76. Mediator.push(CommunityRouterModuleType.pushPostDetailVoide(postId: "\(communityRecommendTypeDataModel?.id ?? 0)", departType: .hotVideos, topicId: 0))
  77. }
  78. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  79. return CGSize(width:131, height: 231)
  80. }
  81. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
  82. return UIEdgeInsets(top: 0, left: 14, bottom: 10, right: 14)
  83. }
  84. }