PublishSelTopicCollectionCell.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // PublishSelTopicCollectionCell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/6/17.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. // 话题类别のCell
  8. import UIKit
  9. import RxSwift
  10. class PublishSelTopicCollectionCell: UICollectionViewCell {
  11. let disposeBag = DisposeBag()
  12. var subTopicModel: CommunityTopicDataModel? {
  13. didSet {
  14. titleLabel.text = self.subTopicModel?.name
  15. }
  16. }
  17. typealias DeleteClosure = (_ index: Int) -> Void
  18. var deleteClosure : DeleteClosure?
  19. class func cellWith(collectionView:UICollectionView,indexPath:IndexPath) -> PublishSelTopicCollectionCell {
  20. let ID = "PublishSelTopicCollectionCell"
  21. collectionView.register(PublishSelTopicCollectionCell.self, forCellWithReuseIdentifier: ID)
  22. let cell : PublishSelTopicCollectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: ID, for: indexPath) as! PublishSelTopicCollectionCell
  23. cell.indexPath = indexPath
  24. return cell
  25. }
  26. //MARK: - indexPath
  27. var indexPath: IndexPath?{
  28. didSet {
  29. }
  30. }
  31. //MARK: - 初始化
  32. override init(frame: CGRect) {
  33. super.init(frame: frame)
  34. backgroundColor = kffffffColor
  35. cornerRadius = 12
  36. masksToBounds = true
  37. setupViews()
  38. setupLayouts()
  39. }
  40. required init?(coder aDecoder: NSCoder) {
  41. fatalError("init(coder:) has not been implemented")
  42. }
  43. //MRAK: - 设置View
  44. private func setupViews() {
  45. addSubview(iconImageView)
  46. addSubview(titleLabel)
  47. addSubview(deleteButton)
  48. }
  49. private func setupLayouts() {
  50. iconImageView.snp.makeConstraints { (make) in
  51. make.top.equalTo(5)
  52. make.left.equalTo(6)
  53. make.size.equalTo(16)
  54. }
  55. titleLabel.snp.makeConstraints { (make) in
  56. make.top.equalTo(3)
  57. make.left.equalTo(iconImageView.snp_right).offset(5)
  58. make.right.equalTo(-26)
  59. make.height.equalTo(19)
  60. }
  61. deleteButton.snp.makeConstraints { (make) in
  62. make.left.equalTo(titleLabel.snp_right).offset(2)
  63. make.right.equalTo(-2)
  64. make.size.equalTo(22)
  65. }
  66. }
  67. private lazy var iconImageView: UIImageView = {
  68. let iconImageView = UIImageView()
  69. iconImageView.image = kImage(name: "edit_ico_topic_pre")
  70. return iconImageView
  71. }()
  72. private lazy var titleLabel: UILabel = {
  73. let titleLabel = UILabel()
  74. titleLabel.textColor = k666666Color
  75. titleLabel.font = kRegularFont13
  76. titleLabel.textAlignment = .left
  77. return titleLabel
  78. }()
  79. private lazy var deleteButton: UIButton = {
  80. let deleteButton = UIButton(type: UIButton.ButtonType.custom)
  81. deleteButton.setImage(kImage(name: "edit_topic_delete"), for: UIControl.State.normal)
  82. deleteButton.rx.tap.subscribe(onNext: { (data) in
  83. if let deleteClosure = self.deleteClosure {
  84. deleteClosure(self.indexPath!.row)
  85. }
  86. }).disposed(by: disposeBag)
  87. return deleteButton
  88. }()
  89. }