PublishEditDescribeCell.swift 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // PublishEditDescribeCell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/6/17.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. import RxSwift
  10. import IQKeyboardManagerSwift
  11. class PublishEditDescribeCell: UITableViewCell {
  12. let disposeBag = DisposeBag()
  13. typealias CommentTextViewClosure = (_ text: String) -> Void
  14. var commentTextViewClosure : CommentTextViewClosure?
  15. class func cellWith(tableView:UITableView,indexPath:IndexPath) -> PublishEditDescribeCell {
  16. let ID = "PublishEditDescribeCell"
  17. tableView.register(PublishEditDescribeCell.self, forCellReuseIdentifier: ID)
  18. let cell : PublishEditDescribeCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! PublishEditDescribeCell
  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. var indexPath: IndexPath? {
  31. didSet {
  32. }
  33. }
  34. //MRAK: - 设置View
  35. private func setupViews() {
  36. self.selectionStyle = .none
  37. addSubview(cmtTextView)
  38. }
  39. private func setupLayouts() {
  40. cmtTextView.snp.makeConstraints { (make) in
  41. make.top.bottom.equalToSuperview()
  42. make.left.equalTo(14)
  43. make.right.equalTo(-14)
  44. }
  45. }
  46. private lazy var cmtTextView: IQTextView = {
  47. let cmtTextView = IQTextView()
  48. cmtTextView.backgroundColor = kffffffColor
  49. cmtTextView.textColor = k333333Color
  50. cmtTextView.font = kRegularFont14
  51. cmtTextView.placeholder = "说一说你的美好心得..."
  52. cmtTextView.placeholderTextColor = kDDDDDDColor
  53. cmtTextView.delegate = self
  54. return cmtTextView
  55. }()
  56. }
  57. extension PublishEditDescribeCell: UITextViewDelegate {
  58. func textViewDidChange(_ textView: UITextView) {
  59. if textView == cmtTextView {
  60. var fullStr = textView.text ?? ""
  61. if textView.text?.count ?? 0 > 180 {
  62. fullStr = String(fullStr.prefix(150)) as String
  63. textView.text = fullStr
  64. }
  65. if let commentTextViewClosure = self.commentTextViewClosure {
  66. commentTextViewClosure(self.cmtTextView.text ?? "")
  67. }
  68. }
  69. }
  70. }