CommunityMyFollowTopicCell.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // CommunityMyFollowTopicCell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/6/12.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. import RxSwift
  10. import RxCocoa
  11. class CommunityMyFollowTopicCell: UITableViewCell {
  12. let disposeBag = DisposeBag()
  13. typealias FocusClickClosure = (_ isFocusSelected: Int) -> Void
  14. var focusClickClosure : FocusClickClosure?
  15. class func cellWith(tableView:UITableView,indexPath:IndexPath) -> CommunityMyFollowTopicCell {
  16. let ID = "CommunityMyFollowTopicCell"
  17. tableView.register(CommunityMyFollowTopicCell.self, forCellReuseIdentifier: ID)
  18. let cell : CommunityMyFollowTopicCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! CommunityMyFollowTopicCell
  19. cell.indexPath = indexPath
  20. return cell
  21. }
  22. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  23. super.init(style: style, reuseIdentifier: reuseIdentifier)
  24. setupViews()
  25. setupLayouts()
  26. }
  27. required init?(coder aDecoder: NSCoder) {
  28. fatalError("init(coder:) has not been implemented")
  29. }
  30. var indexPath: IndexPath? {
  31. didSet {
  32. }
  33. }
  34. //MRAK: - 设置View
  35. private func setupViews() {
  36. self.selectionStyle = .none
  37. backgroundColor = kffffffColor
  38. addSubview(titleLabel)
  39. addSubview(focusButton)
  40. addSubview(sepView)
  41. }
  42. private func setupLayouts() {
  43. titleLabel.snp.makeConstraints { (make) in
  44. make.top.equalTo(20)
  45. make.left.equalTo(14)
  46. make.right.equalToSuperview().offset(-92)
  47. make.height.equalTo(21)
  48. }
  49. focusButton.snp.makeConstraints { (make) in
  50. make.top.equalTo(18)
  51. make.right.equalToSuperview().offset(-14)
  52. make.width.equalTo(64)
  53. make.height.equalTo(26)
  54. }
  55. sepView.snp.makeConstraints { (make) in
  56. make.left.equalTo(titleLabel.snp_left)
  57. make.right.equalTo(focusButton.snp_right)
  58. make.bottom.equalToSuperview()
  59. make.height.equalTo(1)
  60. }
  61. }
  62. private lazy var titleLabel: UILabel = {
  63. let titleLabel = UILabel()
  64. titleLabel.text = "空瓶好物合集"
  65. titleLabel.textColor = k333333Color
  66. titleLabel.font = kRegularFont15
  67. titleLabel.textAlignment = .left
  68. return titleLabel
  69. }()
  70. private lazy var focusButton: UIButton = {
  71. let focusButton = UIButton(type: UIButton.ButtonType.custom)
  72. focusButton.setImage(kImage(name: "common_uncheck_icon"), for: UIControl.State.normal)
  73. focusButton.setImage(kImage(name: "common_check_icon"), for: UIControl.State.selected)
  74. focusButton.rx.tap.subscribe(onNext: { [weak self] (data) in
  75. focusButton.isSelected = !focusButton.isSelected
  76. if let focusClickClosure = self?.focusClickClosure {
  77. let isSel: Int = focusButton.isSelected == true ? 1 : 0
  78. focusClickClosure(isSel)
  79. }
  80. }).disposed(by: disposeBag)
  81. return focusButton
  82. }()
  83. private lazy var sepView: UIView = {
  84. let sepView = UIView()
  85. sepView.backgroundColor = kf5f5f5Color
  86. return sepView
  87. }()
  88. }