MainPublishTableViewCell.swift 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // MainPublishTableViewCell.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2017/3/7.
  6. // Copyright © 2017年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. class MainPublishTableViewCell: UITableViewCell {
  10. var publishInfos:[CMS_PublishInfo] = [] {
  11. didSet {
  12. self.publishCollectionView.reloadData()
  13. }
  14. }
  15. @IBOutlet weak var publishCollectionView: UICollectionView!
  16. override func awakeFromNib() {
  17. super.awakeFromNib()
  18. self.contentView.backgroundColor = UIColor.green
  19. self.publishCollectionView.frame = CGRect(origin:CGPoint(x:0,y:0), size: self.bounds.size)
  20. //self.publishCollectionView.backgroundColor = UIColor.blue
  21. self.publishCollectionView.delegate = self
  22. self.publishCollectionView.dataSource = self
  23. }
  24. override func setSelected(_ selected: Bool, animated: Bool) {
  25. super.setSelected(selected, animated: animated)
  26. // Configure the view for the selected state
  27. }
  28. }
  29. extension MainPublishTableViewCell:UICollectionViewDelegateFlowLayout,UICollectionViewDataSource{
  30. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  31. return 1
  32. }
  33. func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
  34. if kind == UICollectionView.elementKindSectionHeader {
  35. let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "MainPublishHeaderView", for: indexPath)
  36. return headerView
  37. }else if kind == UICollectionView.elementKindSectionFooter{
  38. let footerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "MainPublishFooterView", for: indexPath)
  39. return footerView
  40. }
  41. return UICollectionReusableView()
  42. }
  43. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  44. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MainPublishContentCell", for: indexPath) as! MainPublishContentCell
  45. cell.publishInfos.removeAll(keepingCapacity: true)
  46. cell.publishInfos.append(contentsOf: self.publishInfos)
  47. return cell
  48. }
  49. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  50. return CGSize(width:SCREEN_WIDTH - 125.0, height: 100.0)
  51. }
  52. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
  53. return UIEdgeInsets(top: 1, left: 1, bottom: 1, right: 1)
  54. }
  55. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
  56. return CGSize(width: 65.0,height: 100.0)
  57. }
  58. func collectionView(_ collectionView:UICollectionView,layout collectionViewLayout:UICollectionViewLayout,referenceSizeForFooterInSection section: Int) -> CGSize {
  59. return CGSize(width: 60.0,height: 100.0)
  60. }
  61. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
  62. return 0.5
  63. }
  64. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
  65. return 0.5
  66. }
  67. }