CommunityFeaturedTopicsHeaderView.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // CommunityFeaturedTopicsHeaderView.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/6/16.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. class CommunityFeaturedTopicsHeaderView: BaseView {
  10. override func setupViews() {
  11. self.backgroundColor = UIColor.clear
  12. addSubview(numberPeopleLabel)
  13. addSubview(topicLabel)
  14. addSubview(focusButton)
  15. addSubview(bottomView)
  16. }
  17. override func setupLayouts() {
  18. numberPeopleLabel.snp_makeConstraints { (make) in
  19. make.top.equalTo(92+kSafeStatusBarHeight)
  20. make.left.equalTo(14)
  21. make.height.equalTo(19)
  22. make.right.equalTo(-14)
  23. }
  24. topicLabel.snp_makeConstraints { (make) in
  25. make.top.equalTo(numberPeopleLabel.snp_bottom).offset(8)
  26. make.left.equalTo(14)
  27. make.right.lessThanOrEqualTo(focusButton.snp_left).offset(-5)
  28. make.height.equalTo(33)
  29. }
  30. focusButton.snp_makeConstraints { (make) in
  31. make.centerY.equalTo(topicLabel)
  32. make.right.equalTo(-14)
  33. make.height.equalTo(28)
  34. make.width.equalTo(80)
  35. }
  36. }
  37. private lazy var numberPeopleLabel: UILabel = {
  38. let numberPeopleLabel = UILabel()
  39. numberPeopleLabel.text = "8888位彩虹居民参与此话题"
  40. numberPeopleLabel.textColor = kffffffColor
  41. numberPeopleLabel.font = kRegularFont13
  42. return numberPeopleLabel
  43. }()
  44. private lazy var topicLabel: UILabel = {
  45. let topicLabel = UILabel()
  46. topicLabel.textColor = kffffffColor
  47. topicLabel.font = kMediumFont24
  48. return topicLabel
  49. }()
  50. typealias FollowClosureName = () -> Void
  51. var followClosureName : FollowClosureName?
  52. private lazy var focusButton: UIButton = {
  53. let focusButton = UIButton(type: UIButton.ButtonType.custom)
  54. focusButton.setTitleColor(kffffffColor, for: UIControl.State.selected)
  55. focusButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
  56. focusButton.setTitle("关注话题", for: UIControl.State.normal)
  57. focusButton.setTitle("已关注", for: UIControl.State.selected)
  58. focusButton.titleLabel?.font = kRegularFont13
  59. focusButton.setBackgroundImage(UIImage.imageWithColor(color: kThemeColor), for: UIControl.State.normal)
  60. focusButton.setBackgroundImage(UIImage.imageWithColor(color: UIColor.clear), for: UIControl.State.selected)
  61. focusButton.layer.borderWidth = 0.5
  62. focusButton.cornerRadius = 14
  63. focusButton.masksToBounds = true
  64. focusButton.rx.tap.subscribe(onNext: { [weak self] (data) in
  65. if let followClosureName = self?.followClosureName {
  66. followClosureName()
  67. }
  68. }).disposed(by: disposeBag)
  69. return focusButton
  70. }()
  71. private lazy var bottomView: UIView = {
  72. let bottomView = UIView(frame: CGRect(x: 0, y: 180+kSafeStatusBarHeight, width: kScreenWidth, height: 20))
  73. bottomView.backgroundColor = .white
  74. let shapeLayer = CAShapeLayer()
  75. bottomView.layer.mask = nil
  76. let bezierPath = UIBezierPath(roundedRect: bottomView.bounds,byRoundingCorners: [.topLeft,.topRight],cornerRadii: CGSize(width: 8,height: 8))
  77. shapeLayer.path = bezierPath.cgPath
  78. bottomView.layer.mask = shapeLayer
  79. return bottomView
  80. }()
  81. var communityTopicDetailModel : CommunityTopicDetailModel? {
  82. didSet {
  83. numberPeopleLabel.text = "\(communityTopicDetailModel?.followCount ?? "0")位彩虹居民参与此话题"
  84. topicLabel.text = communityTopicDetailModel?.name
  85. CommunityFollowTopicViewModel.shared.followTopicButton(communityTopicDetailModel: communityTopicDetailModel!, button: focusButton)
  86. }
  87. }
  88. }