RecommendDefaultBackCell.swift 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // RecommendDefaultBackCell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/6/14.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. // 推荐图文内容--缺省Cell
  8. import UIKit
  9. import RxSwift
  10. class RecommendDefaultBackCell: UITableViewCell {
  11. let disposeBag = DisposeBag()
  12. typealias JumpClosure = () -> Void
  13. var jumpClosure : JumpClosure?
  14. class func cellWith(tableView:UITableView,indexPath:IndexPath) -> RecommendDefaultBackCell {
  15. let ID = "RecommendDefaultBackCell"
  16. tableView.register(RecommendDefaultBackCell.self, forCellReuseIdentifier: ID)
  17. let cell : RecommendDefaultBackCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! RecommendDefaultBackCell
  18. cell.indexPath = indexPath
  19. return cell
  20. }
  21. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  22. super.init(style: style, reuseIdentifier: reuseIdentifier)
  23. setupViews()
  24. setupLayouts()
  25. }
  26. required init?(coder aDecoder: NSCoder) {
  27. fatalError("init(coder:) has not been implemented")
  28. }
  29. var indexPath: IndexPath? {
  30. didSet {
  31. }
  32. }
  33. //MRAK: - 设置View
  34. private func setupViews() {
  35. self.selectionStyle = .none
  36. backgroundColor = kffffffColor
  37. addSubview(backImageView)
  38. addSubview(contentLabel)
  39. addSubview(jumpBtn)
  40. }
  41. private func setupLayouts() {
  42. backImageView.snp.makeConstraints { (make) in
  43. make.top.equalTo(50)
  44. make.centerX.equalToSuperview()
  45. make.size.equalTo(120)
  46. }
  47. contentLabel.snp.makeConstraints { (make) in
  48. make.top.equalTo(backImageView.snp_bottom).offset(20)
  49. make.centerX.equalToSuperview()
  50. make.height.equalTo(20)
  51. }
  52. jumpBtn.snp.makeConstraints { (make) in
  53. make.top.equalTo(contentLabel.snp_bottom).offset(20)
  54. make.centerX.equalToSuperview()
  55. make.width.equalTo(180)
  56. make.height.equalTo(32)
  57. }
  58. }
  59. private lazy var backImageView : UIImageView = {
  60. let backImageView = UIImageView()
  61. backImageView.image = kImage(name: "page05")
  62. return backImageView
  63. }()
  64. private lazy var contentLabel: UILabel = {
  65. let contentLabel = UILabel()
  66. contentLabel.text = "内容飞走了,去看看别的吧"
  67. contentLabel.textColor = k666666Color
  68. contentLabel.font = kRegularFont14
  69. contentLabel.textAlignment = .center
  70. return contentLabel
  71. }()
  72. private lazy var jumpBtn: UIButton = {
  73. let jumpBtn = UIButton(type: UIButton.ButtonType.custom)
  74. jumpBtn.backgroundColor = k62CC74Color
  75. jumpBtn.setTitle("去首页", for: .normal)
  76. jumpBtn.setTitleColor(kffffffColor, for: .normal)
  77. jumpBtn.titleLabel?.font = kMediumFont16
  78. jumpBtn.cornerRadius = 16
  79. jumpBtn.masksToBounds = true
  80. jumpBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
  81. if let jumpClosure = self?.jumpClosure {
  82. jumpClosure()
  83. }
  84. }).disposed(by: disposeBag)
  85. return jumpBtn
  86. }()
  87. }