123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- //
- // PublishEditDescribeCell.swift
- // RainbowPlanet
- //
- // Created by Christopher on 2019/6/17.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- //
- import UIKit
- import RxSwift
- import IQKeyboardManagerSwift
- class PublishEditDescribeCell: UITableViewCell {
-
- let disposeBag = DisposeBag()
-
- typealias CommentTextViewClosure = (_ text: String) -> Void
- var commentTextViewClosure : CommentTextViewClosure?
-
- class func cellWith(tableView:UITableView,indexPath:IndexPath) -> PublishEditDescribeCell {
- let ID = "PublishEditDescribeCell"
- tableView.register(PublishEditDescribeCell.self, forCellReuseIdentifier: ID)
- let cell : PublishEditDescribeCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! PublishEditDescribeCell
- 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() {
- self.selectionStyle = .none
-
- addSubview(cmtTextView)
- }
-
- private func setupLayouts() {
- cmtTextView.snp.makeConstraints { (make) in
- make.edges.equalToSuperview()
- }
- }
-
- private lazy var cmtTextView: IQTextView = {
- let cmtTextView = IQTextView()
- cmtTextView.backgroundColor = kffffffColor
- cmtTextView.textColor = k333333Color
- cmtTextView.font = kRegularFont14
- cmtTextView.placeholder = "说一说你的美好心得..."
- cmtTextView.placeholderTextColor = k999999Color
- cmtTextView.delegate = self
- return cmtTextView
- }()
-
- }
- extension PublishEditDescribeCell: UITextViewDelegate {
-
- func textViewDidChange(_ textView: UITextView) {
- if textView == cmtTextView {
- var fullStr = textView.text ?? ""
- if textView.text?.count ?? 0 > 180 {
- fullStr = String(fullStr.prefix(150)) as String
- textView.text = fullStr
- }
-
- if let commentTextViewClosure = self.commentTextViewClosure {
- commentTextViewClosure(self.cmtTextView.text ?? "")
- }
- }
- }
-
- }
|