PublishAddressPOICell.swift 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // PublishAddressPOICell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/6/19.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. import RxSwift
  10. import RxCocoa
  11. class PublishAddressPOICell: UITableViewCell {
  12. typealias RefreshButtonBlock = () -> Void
  13. var refreshButtonBlock : RefreshButtonBlock?
  14. let disposeBag = DisposeBag()
  15. class func cellWith(tableView:UITableView,indexPath:IndexPath) -> PublishAddressPOICell {
  16. let ID = "PublishAddressPOICell"
  17. tableView.register(PublishAddressPOICell.self, forCellReuseIdentifier: ID)
  18. let cell : PublishAddressPOICell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! PublishAddressPOICell
  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. //MARK: - indexPath
  31. var indexPath: IndexPath?{
  32. didSet {
  33. switch indexPath?.section {
  34. case 0:
  35. self.refreshButton.isHidden = false
  36. default:
  37. self.refreshButton.isHidden = true
  38. }
  39. }
  40. }
  41. var suggestionInfo: BMKSuggestionInfo? {
  42. didSet {
  43. switch indexPath?.section {
  44. case 1:
  45. titleLabel.text = self.suggestionInfo!.district + self.suggestionInfo!.key
  46. default:
  47. break
  48. }
  49. }
  50. }
  51. var locationAddress: String? {
  52. didSet {
  53. if locationAddress != "" && locationAddress != nil {
  54. titleLabel.text = locationAddress
  55. }else {
  56. titleLabel.text = LocationModel.shared().getLocationModel()?.city ?? "西安市"
  57. }
  58. }
  59. }
  60. //MARK: - 设置view
  61. private func setupViews() {
  62. self.selectionStyle = .none
  63. addSubview(titleLabel)
  64. addSubview(refreshButton)
  65. addSubview(bottomLineLabel)
  66. }
  67. private func setupLayouts() {
  68. titleLabel.snp.makeConstraints { (make) in
  69. make.centerY.equalToSuperview()
  70. make.left.equalTo(14)
  71. make.right.equalTo(-14)
  72. make.height.equalTo(21)
  73. }
  74. refreshButton.snp.makeConstraints { (make) in
  75. make.top.equalTo(titleLabel)
  76. make.right.equalToSuperview().offset(kScaleValue(value: -14))
  77. make.width.equalTo(kScaleValue(value: 46))
  78. }
  79. refreshButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 2)
  80. bottomLineLabel.snp.makeConstraints { (make) in
  81. make.bottom.equalToSuperview()
  82. make.left.equalTo(titleLabel.snp_left)
  83. make.right.equalTo(titleLabel.snp_right)
  84. make.height.equalTo(0.5)
  85. }
  86. }
  87. private lazy var titleLabel: UILabel = {
  88. let titleLabel = UILabel()
  89. titleLabel.textColor = k333333Color
  90. titleLabel.font = kMediumFont15
  91. titleLabel.textAlignment = .left
  92. titleLabel.numberOfLines = 0
  93. return titleLabel
  94. }()
  95. private lazy var refreshButton : UIButton = {
  96. let refreshButton = UIButton()
  97. refreshButton.setImage(kImage(name: "navbar_refresh"), for: UIControl.State.normal)
  98. refreshButton.setTitle("刷新", for: UIControl.State.normal)
  99. refreshButton.setTitleColor(kFFA42FColor, for: UIControl.State.normal)
  100. refreshButton.titleLabel?.font = kRegularFont14
  101. refreshButton.isHidden = true
  102. refreshButton.rx.tap.subscribe(onNext: { [weak self] (data) in
  103. if self?.indexPath?.section == 0 {
  104. if let refreshButtonBlock = self?.refreshButtonBlock {
  105. refreshButtonBlock()
  106. }
  107. }
  108. }).disposed(by: disposeBag)
  109. return refreshButton
  110. }()
  111. private lazy var bottomLineLabel: UILabel = {
  112. let bottomLineLabel = UILabel()
  113. bottomLineLabel.backgroundColor = kf5f5f5Color
  114. return bottomLineLabel
  115. }()
  116. }