Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import Eureka
- import SnapKit
- class EditProfileAboutMeCell: Cell<String>, CellType, UITextViewDelegate {
- private let titleLabel = UILabel()
- private let valueTextView = UITextView()
- private let bottomSeparator = UIView()
- override func setup() {
- super.setup()
- addSubview(titleLabel)
- titleLabel.textColor = UIColor.gray
- titleLabel.snp.makeConstraints { (make) in
- make.top.equalToSuperview().offset(12)
- make.left.equalToSuperview().offset(15)
- make.width.equalToSuperview().multipliedBy(0.3)
- }
- addSubview(bottomSeparator)
- bottomSeparator.backgroundColor = UIColor.gray
- bottomSeparator.snp.makeConstraints { (make) in
- make.bottom.right.equalToSuperview()
- make.left.equalTo(titleLabel.snp.right).offset(8)
- make.height.equalTo(1)
- }
- addSubview(valueTextView)
- valueTextView.textColor = UIColor.black
- valueTextView.snp.makeConstraints { (make) in
- make.right.equalToSuperview()
- make.bottom.equalTo(bottomSeparator.snp.top)
- make.top.equalToSuperview()
- make.left.equalTo(titleLabel.snp.right).offset(8)
- }
- selectionStyle = .none
- valueTextView.delegate = self
- }
- override func update() {
- super.update()
- guard let row = row as? EditProfileAboutMeRow else { return }
- row.title = nil
- titleLabel.text = row.rowTitle
- valueTextView.text = row.value
- }
- // MARK: UITextViewDelegate
- func textView(_ textView: UITextView,
- shouldChangeTextIn range: NSRange,
- replacementText text: String) -> Bool {
- guard let currentText = textView.text, let row = row as? EditProfileAboutMeRow else { return true }
- let newLength = currentText.count + text.count - range.length
- return newLength <= row.maximumLength
- }
- // MARK: Text field helper
- @objc func textViewDidChange(_ textView: UITextView) {
- row.value = textView.text
- }
- }
- final class EditProfileAboutMeRow: Row<EditProfileAboutMeCell>, RowType {
- var maximumLength: Int = 150
- var placeholder: String?
- var rowTitle: String?
- required init(tag: String?) {
- super.init(tag: tag)
- displayValueFor = nil
- }
- init() {
- super.init(tag: nil)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement