123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- //
- // CommunityReplyCommentCell.swift
- // RainbowPlanet
- //
- // Created by Christopher on 2019/6/12.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- // 二级评论--评论回复のCell
- import UIKit
- import RxSwift
- import Kingfisher
- class CommunityReplyCommentCell: UITableViewCell {
-
- let disposeBag = DisposeBag()
-
- class func cellWith(tableView:UITableView,indexPath:IndexPath) -> CommunityReplyCommentCell {
- let ID = "CommunityReplyCommentCell"
- tableView.register(CommunityReplyCommentCell.self, forCellReuseIdentifier: ID)
- let cell : CommunityReplyCommentCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! CommunityReplyCommentCell
- cell.indexPath = indexPath
- return cell
- }
-
- override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- setupViews()
- setupLayouts()
- }
-
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- var indexPath: IndexPath? {
- didSet {
-
- }
- }
-
- //MRAK: - 设置View
- private func setupViews() {
-
- backgroundColor = kf7f8faColor
-
- addSubview(iconButton)
- addSubview(titleLabel)
- addSubview(contentLabel)
- addSubview(timeLabel)
- }
-
- private func setupLayouts() {
- iconButton.snp.makeConstraints { (make) in
- make.top.equalTo(0)
- make.left.equalTo(24)
- make.size.equalTo(24)
- }
- titleLabel.snp.makeConstraints { (make) in
- make.left.equalTo(iconButton.snp_right).offset(10)
- make.right.equalToSuperview().offset(-10)
- make.centerY.equalTo(iconButton)
- make.height.equalTo(17)
- }
- contentLabel.snp.makeConstraints { (make) in
- make.top.equalTo(titleLabel.snp_bottom).offset(12)
- make.left.equalTo(titleLabel.snp_left)
- make.right.equalToSuperview().offset(-10)
- make.width.equalTo(kScreenWidth-62-54)
- }
- timeLabel.snp.makeConstraints { (make) in
- make.top.equalTo(contentLabel.snp_bottom).offset(8)
- make.left.equalTo(titleLabel.snp_left)
- make.right.equalTo(contentLabel.snp_right)
- make.height.equalTo(15)
- }
- }
-
- private lazy var iconButton : UIButton = {
- let iconButton = UIButton(type: UIButton.ButtonType.custom)
- iconButton.setImage(kImage(name: "default_avatar"), for: UIControl.State.normal)
- iconButton.cornerRadius = 12
- iconButton.masksToBounds = true
- iconButton.isUserInteractionEnabled = false
- iconButton.rx.tap.subscribe(onNext: { [weak self] (data) in
-
- }).disposed(by: disposeBag)
- return iconButton
- }()
-
- private lazy var titleLabel: UILabel = {
- let titleLabel = UILabel()
- titleLabel.textColor = k999999Color
- titleLabel.font = kRegularFont14
- titleLabel.textAlignment = .left
- return titleLabel
- }()
-
- private lazy var contentLabel: FMLinkLabel = {
- let contentLabel = FMLinkLabel()
- contentLabel.textColor = k333333Color
- contentLabel.font = kRegularFont14
- contentLabel.textAlignment = .left
- contentLabel.numberOfLines = 0
- contentLabel.isUserInteractionEnabled = false
- return contentLabel
- }()
-
- lazy var timeLabel: UILabel = {
- let timeLabel = UILabel()
- timeLabel.textColor = kbbbbbbColor
- timeLabel.font = kRegularFont12
- timeLabel.textAlignment = .left
- return timeLabel
- }()
-
- var communityPostReplyModel: CommunityPostReplyModel? {
- didSet {
- iconButton.kf.setImage(with: kURLThumbnailsImage(name: communityPostReplyModel?.avatar ?? "",size: kSize24x24Image), for: UIControl.State.normal, placeholder: kImage(name: "default_avatar"))
- KingfisherManager.shared.cache.clearMemoryCache()
-
- titleLabel.text = communityPostReplyModel?.username
-
- let replyUsername = "回复 @\(communityPostReplyModel?.replyUsername ?? ""):"
- let content = "\(communityPostReplyModel?.content ?? "")"
- if communityPostReplyModel?.replyUsername != "" && communityPostReplyModel?.replyUsername != nil {
- contentLabel.text = replyUsername + content
- contentLabel.addClickText("@\(communityPostReplyModel?.replyUsername ?? "")", attributeds: [NSAttributedString.Key.font:kMediumFont14 as Any], transmitBody: nil) {
- (data) in
-
- }
- }else {
- contentLabel.text = content
- }
-
- timeLabel.text = communityPostReplyModel?.createdAt
- let contentLabelHeight = contentLabel.text?.heightForComment(font: kRegularFont14!, width: kScreenWidth - 58 - 14)
- let subViewHeight = 24.0 + (contentLabelHeight ?? 0) + 15.0
- let spacHeight = 10.0 + 8.0 + 8.0
- communityPostReplyModel?.height = CGFloat(subViewHeight) + CGFloat(spacHeight)
- }
- }
-
- }
|