CommunityReplyCommentCell.swift 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // CommunityReplyCommentCell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/6/12.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. // 二级评论--评论回复のCell
  8. import UIKit
  9. import RxSwift
  10. import Kingfisher
  11. class CommunityReplyCommentCell: UITableViewCell {
  12. let disposeBag = DisposeBag()
  13. class func cellWith(tableView:UITableView,indexPath:IndexPath) -> CommunityReplyCommentCell {
  14. let ID = "CommunityReplyCommentCell"
  15. tableView.register(CommunityReplyCommentCell.self, forCellReuseIdentifier: ID)
  16. let cell : CommunityReplyCommentCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! CommunityReplyCommentCell
  17. cell.indexPath = indexPath
  18. return cell
  19. }
  20. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  21. super.init(style: style, reuseIdentifier: reuseIdentifier)
  22. setupViews()
  23. setupLayouts()
  24. }
  25. required init?(coder aDecoder: NSCoder) {
  26. fatalError("init(coder:) has not been implemented")
  27. }
  28. var indexPath: IndexPath? {
  29. didSet {
  30. }
  31. }
  32. //MRAK: - 设置View
  33. private func setupViews() {
  34. backgroundColor = kf7f8faColor
  35. addSubview(iconButton)
  36. addSubview(titleLabel)
  37. addSubview(contentLabel)
  38. addSubview(timeLabel)
  39. }
  40. private func setupLayouts() {
  41. iconButton.snp.makeConstraints { (make) in
  42. make.top.equalTo(0)
  43. make.left.equalTo(24)
  44. make.size.equalTo(24)
  45. }
  46. titleLabel.snp.makeConstraints { (make) in
  47. make.left.equalTo(iconButton.snp_right).offset(10)
  48. make.right.equalToSuperview().offset(-10)
  49. make.centerY.equalTo(iconButton)
  50. make.height.equalTo(17)
  51. }
  52. contentLabel.snp.makeConstraints { (make) in
  53. make.top.equalTo(titleLabel.snp_bottom).offset(12)
  54. make.left.equalTo(titleLabel.snp_left)
  55. make.right.equalToSuperview().offset(-10)
  56. make.width.equalTo(kScreenWidth-62-54)
  57. }
  58. timeLabel.snp.makeConstraints { (make) in
  59. make.top.equalTo(contentLabel.snp_bottom).offset(8)
  60. make.left.equalTo(titleLabel.snp_left)
  61. make.right.equalTo(contentLabel.snp_right)
  62. make.height.equalTo(15)
  63. }
  64. }
  65. private lazy var iconButton : UIButton = {
  66. let iconButton = UIButton(type: UIButton.ButtonType.custom)
  67. iconButton.setImage(kImage(name: "default_avatar"), for: UIControl.State.normal)
  68. iconButton.cornerRadius = 12
  69. iconButton.masksToBounds = true
  70. iconButton.isUserInteractionEnabled = false
  71. iconButton.rx.tap.subscribe(onNext: { [weak self] (data) in
  72. }).disposed(by: disposeBag)
  73. return iconButton
  74. }()
  75. private lazy var titleLabel: UILabel = {
  76. let titleLabel = UILabel()
  77. titleLabel.textColor = k999999Color
  78. titleLabel.font = kRegularFont14
  79. titleLabel.textAlignment = .left
  80. return titleLabel
  81. }()
  82. private lazy var contentLabel: FMLinkLabel = {
  83. let contentLabel = FMLinkLabel()
  84. contentLabel.textColor = k333333Color
  85. contentLabel.font = kRegularFont14
  86. contentLabel.textAlignment = .left
  87. contentLabel.numberOfLines = 0
  88. contentLabel.isUserInteractionEnabled = false
  89. return contentLabel
  90. }()
  91. lazy var timeLabel: UILabel = {
  92. let timeLabel = UILabel()
  93. timeLabel.textColor = kbbbbbbColor
  94. timeLabel.font = kRegularFont12
  95. timeLabel.textAlignment = .left
  96. return timeLabel
  97. }()
  98. var communityPostReplyModel: CommunityPostReplyModel? {
  99. didSet {
  100. iconButton.kf.setImage(with: kURLThumbnailsImage(name: communityPostReplyModel?.avatar ?? "",size: kSize24x24Image), for: UIControl.State.normal, placeholder: kImage(name: "default_avatar"))
  101. KingfisherManager.shared.cache.clearMemoryCache()
  102. titleLabel.text = communityPostReplyModel?.username
  103. let replyUsername = "回复 @\(communityPostReplyModel?.replyUsername ?? ""):"
  104. let content = "\(communityPostReplyModel?.content ?? "")"
  105. if communityPostReplyModel?.replyUsername != "" && communityPostReplyModel?.replyUsername != nil {
  106. contentLabel.text = replyUsername + content
  107. contentLabel.addClickText("@\(communityPostReplyModel?.replyUsername ?? "")", attributeds: [NSAttributedString.Key.font:kMediumFont14 as Any], transmitBody: nil) {
  108. (data) in
  109. }
  110. }else {
  111. contentLabel.text = content
  112. }
  113. timeLabel.text = communityPostReplyModel?.createdAt
  114. let contentLabelHeight = contentLabel.text?.heightForComment(font: kRegularFont14!, width: kScreenWidth - 58 - 14)
  115. let subViewHeight = 24.0 + (contentLabelHeight ?? 0) + 15.0
  116. let spacHeight = 10.0 + 8.0 + 8.0
  117. communityPostReplyModel?.height = CGFloat(subViewHeight) + CGFloat(spacHeight)
  118. }
  119. }
  120. }