FeaturedTopicsTableViewCell.swift 3.3 KB

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